digits - Regex to match 3 numbers -
Currently, I'm trying to create a regex, which can get 3 numbers under some circumstances. I have tried many attempts now, but it will not work with a single expression - it either matches "bad positive" or "wrong numbers" ...
words : I have to get any 3 points which
- is visible at the beginning of a string
- Empiring somewhere inside the string
- (End string not possible)
If:
- Another 3-digit group matching this condition is not.
- Group "p" or "i"
- The group is not followed "x"
in examples Strong> (the number that I want to match) in
() :
- This (321) is an example.
- Also included (321) // Basically not possible, but can not hurt.
- This is another group with AP (321): 122p
- This is another group of (321) I: 123i
- Reasons for this x235 (123) that I want to do.
- (123) What do I want, no x111 or 125p or 999i
- There is no solution in this 111 case 555
(I This is needed (1 number) (2 numbers) - but this will only be a bit change in the match of 3 numbers)
My last attempt looks like this:
( ?: [^ X] | ^) (\ D {1}) (\ d {2}) [^ pi]
However this fails in the final case. I used it for
preg_match_all (... ) === 1 with this Tried to make sure, only one result was matched
However, now a teststring like "101 202" is positive because first check matches
101 (with white spot ) And then does not match the
202 , which assumes the pattern that
101 is the only legitimate solution - which is false.
( ?: [^ x] | ^) (\ d {1}) (\ d {2}) [^ pi]
Any thoughts?
Note: It should work on various regex engines, no matter what php, javascript, java, .net or ook! :)
We can write the numbers you are looking for like this:
re_n = (?: [^ X] | ^) \ d \ d \ d (?: [^ Ip] | $)
Then the whole expression is:
^ (?!. Re_n. * Re_n. * $) * (Re_n)
After the line ends the two numbers using a negative lookhead, start the anchor, then matches a valid number.
Interpolated expression looks useless:
/ ^ (?!. * (?: (? ^ [^ X] | ^) \ d \ d \ d ( [^ Ip] | $)) * (: ([^ x] | ^) \ d \ d \ d (:. ?? [^ ip] | $). * $). * ([? ^ [^ X] | ^) \ d \ d \ d (?: [^ Ip] | $))) /
This perl code:
my $ re_n = qr / (?: [^ X] | ^) \ d \ d \ d (?: [^ Ip] | $) /; While (& lt; data & gt;) {chomp; If (/ ((??) .. ***************** "$ _: $ 1 \ n";} Other {print "$ _: none" \ "";}} __DATA__ This is a 321 example. 321 in 321 is not basically possible, but can not hurt. There is another group with P: 122p this 321 is another group I: 123i This x235 should be ignored because the reason 123 is what I want to match is 123 which is what I want, not 111 in this case x111 Or there is no solution in 125p or 999i 555
produces:
this 321 An example is: 321 321 also: 321/321 is not basically possible, but can not hurt: 321 This 321 has another group with AP: 122 P: 321 In 321 this is the second group with I: 123i: 321 This X-235 should be sponsored because the 123 which I want to match: 123 123 I do not want, x111 or 125p or 999i: 123 There is no solution in this 111 case 555: No
Comments
Post a Comment