RegEx for single asterisk (*) and alphanumeric

Related searches

I need a javascript regex that accepts any alphanumeric character (can be any amount of characters or 0 characters if an asterisk is present) and a single asterisk anywhere in the string (but it does not need the asterisk).

Matches

*
abc
*abc
abc*
a*bc

Invalid Matches

**
*_abc
*abc*
abc**
**abc

I have

^([A-Za-z\d*]?)+$ 

but that matches multiple asterisks and I'm not sure how to only allow one https://regex101.com/r/a1C9bf/1

You may use this regex with a negative lookahead:

/^(?!(?:.*\*){2})[A-Za-z\d*]+$/gm

Updated RegEx Demo

Negative lookahead (?!(?:.*\*){2}) fails the match if there are more than one * in input.

Regular expression characters and usage options, An asterisk (*) instructs UFT to match zero or more occurrences of the preceding character. Matching One of Several Regular Expressions ( | ) Matching Any AlphaNumeric Character Including the Underscore ( \w ). regex to validate email address noteworthy: (1) It allows usernames with 1 or 2 alphanum characters, or 3+ chars can have -._ in the middle. username may NOT start/end with -._ or any other non alphanumeric character. (2) It allows heirarchical domain names (e.g. [email protected]). Similar -._ placement rules there.

You could do:

^(?=.)[A-Za-z\d]*\*?[A-Za-z\d]*$

This will match any string that that's at least one character long ((?=.)), starts with zero or more alphanumeric characters, contains an optional *, and ends with zero or more alphanumeric characters.

You could also replace [A-Za-z\d] with [^\W_] to make it a little shorter (but slightly harder to read):

^(?=.)[^\W_]*\*?[^\W_]*$

Regular Expressions, Regular Expression Syntax � Using Regular Expressions in Custom Sites Asterisk. zero or more occurrences of preceding character. +. Plus Sign. one or more occurrences any word character (underscore or alphanumeric character). \W. For example, the below regular expression matches 4 digits string, and only four digits string because there is ^ at the beginninga nd $ at the end of the regex. ^[\d]{4}$ {n,m} Curly brackets with 2 numbers inside it, matches minimum and maximum number of times of the preceding character.

You want one match one of two possible cases:

  1. an asterisk surrounded by zero or more alphanumeric characters
  2. one or more alphanumeric characters

Then this is your regex:

^([a-zA-Z\d]*\*[a-zA-Z\d]*|[a-zA-Z\d]+)$

Wildcard character, In software, a wildcard character is a kind of placeholder represented by a single character, such as an asterisk 2.1 File and directory patterns; 2.2 Databases; 2.3 Regular expressions automatic link establishment, the wildcard character ? may be substituted for any one of the 36 upper-case alphanumeric characters. The ‹ ^ › and ‹ $ › anchors ensure that the regex matches the entire subject string; otherwise, it could match 10 characters within longer text. The ‹ [A-Z] › character class matches any single uppercase character from A to Z, and the interval quantifier ‹ {1,10} › repeats the character class from 1 to 10 times.

Without requiring any look-ahead, you could use ^([\da-zA-Z]+|[\da-zA-Z]*\*[\da-zA-Z]*)$ https://regex101.com/r/xW2IvR/2

SQLite GLOB: Test If A String Matches A UNIX-Pattern, The asterisk (*) wildcard matches any number of characters. The [a-zA-Z0-9] pattern matches any single alphanumeric character, both lowercase, and� Note: Regular expressions in Content Compliance policies are case sensitive. [:alnum:] Matches alphanumeric characters (letters or digits): a-z, A-Z, or 0-9 Note: This character class must be surrounded with another set of square brackets when you use it in a regular expression, for example: [[:alnum:]]. [:alpha:]

Regular Expressions -- Eloquent JavaScript, Regular expressions are a language for describing patterns in strings. For a start, they allow some of their elements to match more than a single In chapter 6, when extracting mark-up from a document, we needed to find the first asterisk or 'w' ( \w ) matches any alphanumeric character (including underscores, for some� If your regular expression is dynamic, it is better to use the regex constructor method. Regular Expression Methods. If you noticed in the definition section above, I mentioned a regular expression is a type of Object.This means there are a number of methods we can use on our regex. One basic method is .test(), which returns a Boolean:

Searching with Regular Expressions (RegEx) A regular expression is a form of advanced searching that looks for specific patterns, as opposed to certain terms and phrases. With RegEx you can use pattern matching to search for particular strings of characters rather than constructing multiple, literal search queries.

For example, the terminology rule regular expression, "/a.b/", matches all text where there is an "a" followed by any single character, followed by a "b", as in, "a5b". The asterisk matches the preceding pattern or character zero or more times.

Comments
  • Yup, this is the one, thanks! I'll mark it as the answer in a couple minutes :)
  • can you please solve this issue