This question already has answers here:
Matching a space in regex
(10 answers)
Closed 9 years ago.
I use this regular expression for checking
public const string FullNameRegularExpression = #"^[a-zA-Z0-9._-]+$";
How to add "spacebar" in?
If you are looking for one single space it is: (" "), a very complete example can be found in this reference.
Or if you want to match any whitespace character (\n,\r,\f,\t, ), you can use \s.
Notice an added \s
public const string FullNameRegularExpression = #"^[a-zA-Z0-9._-\s]+$";
You may push a spacebar on your keyboard or add \s or \s+ or \s* to your regex ;-)
Related
This question already has answers here:
What is the difference between .*? and .* regular expressions?
(3 answers)
What do 'lazy' and 'greedy' mean in the context of regular expressions?
(13 answers)
Closed 5 months ago.
There is a line of text:
Lorem ~Ipsum~ is simply ~dummy~ text ~of~ the printing...
To find all the words enclosed in ~~ I use
re.search(r'~([^~]*)~', text)
Let's say it became necessary to use ~~ instead of ~
([^\~]+) indicates to exclude the ~ character from the text within those characters
How do I make a regular expression to exclude a string of characters instead of just one?
That is, ~~Lor~em~~ should return Lor~em
The symbol of the new string must not be excluded and the length of the found string cannot be 0
Use a non-greedy quantifier instead of a negated character set.
re.search(r'~~(.*?)~~', text, flags=re.DOTALL)
re.DOTALL makes . match newline characters.
This question already has answers here:
How can I make my match non greedy in vim?
(8 answers)
Closed 4 years ago.
I'we been trying to do simple substitution in vim, and find out that the \? in vim not works with * or +, saying that (NFA regexp) Can't have a multi follow a multi, in the vim:
i want it to stop here, not here
~
~
~
[NORMAL] ...
:%s/^\(.*\?\)here//
If I remove \? it works, but the it regex matches up to 2nd here.
But with normal regex it works: https://regex101.com/r/iHdxxl/1
Why it isn't possible to use \? with * or \+ in vim?
As stated there, you can't add the ? char in vim after the asterisk.
To make the search non greedy, you need to use .\{-} instead of .*:
:%s/\(.\{-}\)here//
Another option is to use negative lookahead:
:%s/\v^((here)#!.)* here//
\v is used for very magic to avoid escaping all over in regex.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I came across someone doing: grep -v "\#". Could someone just quickly explain what happens when you precede a character that is not an escape character (like '#') with a backslash.
\# is a regular expression which matches the literal character #. Infact the backslash is not needed since the regular expression # is simpler and serves the same purpose.
This question already has answers here:
Why do regex constructors need to be double escaped?
(5 answers)
Closed 5 years ago.
pattern: '^131\.[0-9]{6}$',
prettier change it to pattern: '^131.[0-9]{6}$',. Is there a way to ignore line, or ignore file?
Assuming JavaScript (as you're using prettier.) The '^131\.[0-9]{6}$' is just a string, not a regex. Prettier removes unnecessary escape characters when reformatting. As \. isn't a meaningful escape, it's the same as just having . on its own in string context.
Your aim is to get \. into a regex, which I assume you're going to create using the new RegExp() constructor; in that case you want to escape the backslash:
pattern: '^131\\.[0-9]{6}$'
This question already has answers here:
Capturing specific fields on a long string [closed]
(2 answers)
Closed 8 years ago.
This is related to: RegEx: Grabbing values between quotation marks.
If there is a String like this:
HYPERLINK "hyperlink_funda.docx" \l "FunHere" \o "text" \t "_parent"
What regex could return the value enclosed in quotation mark only for switch \l?
FunHere
Assuming there's no escaped " or lines in // comments that should be accounted for:
\\l\s*"([^"]*)
Debuggex Demo Your match will be in group 1.
The following regex will capture the required words in the 1st capture group:
\\l\s*"(\w+)"