This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 3 years ago.
Regex testing for special characters, decimal except for hyphen, commas, alpha-numeric.
Attempt
^(\+|-)?([0-9]+)$/
I'm trying to write a regex to match special characters, decimal except for commas, a hyphen, alpha-numeric.
Welcome!
Maybe, you might just want to list the chars that you wish in a [] and test it. Maybe, a simple expression like this would be desired for you and you could work on it:
^([?!"'~&%$*##0-^#9]+)$
You might want to use this tool and design an expression that you wish, then test it with real samples and maybe change it as you wish.
You can also use an online visualizer to view how your expression would work:
Related
This question already has answers here:
How to find overlapping matches with a regexp?
(4 answers)
Closed 3 years ago.
I'm trying to extract the repeated pattern from a string.
For example with something like "112112112112" I would want to end up with "112".
I've been having problems where I either end up with "1" or "112112".
The patterns can be of any size.
Here's an example of the kind of expressions I've been playing around with.
^(.+)(?=\1)
There are repeated patterns with different sizes, if 3 would be desired, for instance, we'd use a quantifier for that, such as:
(.{3})(?=\1)
Demo 1
or
(.{3,5})(?=\1)
Demo 2
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
Unfortunately I found that the existing examples are confusing and not similar enough to what I am trying to achieve. I need a regular expression to find occurencies of strings like
=> Test[a]
where between the special character > and Test there is exactly one space. The word Test can be replaced by any alphabetic string (=> Apple[b] is another example). I have worked out a regex for all except the first part with the block =>.
Can anyone help me?
I managed to find this expression
.(=>) [a-zA-Z]+\[a\]\.
and it works! Thanks everyone.
Try use this regex:
=> \S+
Here Is Demo
This question already has answers here:
How do I match any character across multiple lines in a regular expression?
(26 answers)
Regex search with pattern containing (?:.|\s)*? takes increasingly long time
(1 answer)
Closed 3 years ago.
A few times I saw regex experts say that using (.|\n)*? is a really, really bad idea.
Well, I do understand that it's better to replace it with the .* and use the /s flag. But sometimes the flags are not available, for example, when using regex within a text editor or other software with limited regex functionality. Thus, using something like (.|\n)*? might be the only option for multi-line matching.
So, what are the reasons to always avoid (.|\n)*??
This question already has answers here:
How do I isolate a space using RegExp in VBA (\s vs. \p{Zs})?
(3 answers)
Closed 4 years ago.
I am having a similar issue as this question here. \s is not matching all white spaces in VBA.
But I want to catch all kinds of whitespace - spaces, tabs, newlines, thin space, hair space etc. and not only one of them.
Is there another possibility than hard coding every unicode value like the following?
With regEx
.Global = True
.Pattern = "(\s|\u2009|\u2008|.............)"
End With
How do I isolate a space using RegExp in VBA (\s vs. \p{Zs})? wants to isolate spaces - I want readable and reliable way to match any whitespace without needing to list the unicode values for them as proposed by the one who closed the question.
There is no perfect alternative, therefore I suggest to use exact values/codes.
You should be safe with this regex pattern:
[\s\n\r\t \xA0\u1680\u180E\u2000-\u200B\u202F\u205F\u3000\uFEFF]+
This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 5 years ago.
I've tried to make a regular expression that match anything except if contains a 11 digits like 12345678910 so don't match anything
what i have tried
[^\d{11}]
but {11} doesn't work with \d expression
so what i have to do ?
you can use the regex
^(?!.*\d{11}).*$
see the regex101 demo
It's not a very good task for regex to solve actually, because you have to describe every string that doesn't contain 11 consecutive digits.
If possible, I suggest matching a string that does contain 11 consecutive digits, then inverting the success of that match with the language or tool from which you execute this regex.
Depending on your regex flavour, you might also be able to use a negative lookahead such as presented in other answers.
This seemed to work for me using a negative look around:
/^((?!\d{11}).)*$/gm