2

I'm using an API which is checking values with php preg_match method. I can only use original value (I can't prepare it) and regex expression. Value is a multiple line string like

12 value;
13 value;
14 value;

Now I need to check if every line matches my regex expression which is for single line would be like '/^\d+\s\w+\;$/'. So the correct regex would return true (1) for the previous value and false (0) for the value below:

12 value;
13 ;
14 value;

Is that possible?

2 Answers 2

2

Include dotall modifier and then repeat the (current pattern + newline char at the start) zero or more times.

'/^\d+\h\w+;(?:\n\d+\h\w+;)*$/s'

In DOTALL mode, ^ matches the start of very first line. And $ matches the end of very last line. And also I replaced \s with \h because \s will match all the spaces and also the line breaks. Though \h will also match single space and a tab , for an exact thing, include space only instead of \h

Sign up to request clarification or add additional context in comments.

5 Comments

really, then there must be a need to edit the doc. See the markers in regex101.com/r/oC5rY5/7 and regex101.com/r/oC5rY5/8
My bad, misread that part. But the /s modifier has no effect on your regex, since it contains no ..
But it contains anchors.
So? Those aren't affected by /s: regex101.com/r/oC5rY5/7 vs regex101.com/r/gE5xQ7/2
ya, it also works without modifiers. But not with m modifier.
2
^\d+\s\w+\;(?:\n\d+\s\w+\;)*$

Try this.See demo.

https://regex101.com/r/oC5rY5/5

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.