I've been looking to create a regex for my specific situation. The furthest i've come with my own limited knowledge of Regex and by searching on StackOverflow is this Regex:
^[pP][a-zA-Z0-9- ]*
I'm looking for a Regex which forces the string to:
Examples of strings that should match the Regex:
What is the Regex I'm looking for? The language I'm using is C#
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
The meta character “^” matches the beginning of a particular string i.e. it matches the first character of the string. For example, The expression “^\d” matches the string/line starting with a digit. The expression “^[a-z]” matches the string/line starting with a lower case alphabet.
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1. 1* means any number of ones.
Adding to @Zenoo's answer, if you want to take into account %20
as a single occurrence, you can use the following expression:
[pP]([a-zA-Z0-9 +-]|(%20)){14,}0000
where you basically add to the possible character list %20
as a single occurrence.
Here is the live demo, which you can use to test all the examples you want (I already included those you provided), with all the technical explanations needed, which I am copying below:
You could try this RegEx : [pP][a-zA-Z0-9- +%]{13,}0000
[pP]
matches a single character in the list pP
(case sensitive)
{13,}
matches 13 or more iterations of [a-zA-Z0-9- +%]
a-z
a single character in the range between a
(index 97) and z
(index 122) (case sensitive)A-Z
a single character in the range between A
(index 65) and Z
(index 90) (case sensitive)0-9
a single character in the range between 0
(index 48) and 9
(index 57) (case sensitive)- +%
matches a single character in the list - +%
(case sensitive)0000
matches the characters 0000
literally (case sensitive)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With