Meaning of (?s) in a regular expression.

Asked 2 years ago, Updated 2 years ago, 73 views

I can't find the meaning of (?s) even if I keep looking for it, I don't know what it means. What is the role of (?s) in a regular expression?

regex

2022-09-22 21:59

3 Answers

It's a single line modifier.

In regex, which I've used,

/ Regular expression/s

I put on the modifier at the end I think it's okay to write it after the parenthesis and the question mark.

When you use a single line modifier, .(all) contains new lines.

I think you can think of Modifier as an option for regular expressions.


2022-09-22 21:59

The regular expression . does not match open characters by default. The flag to turn this off/set is the s flag. (Use s when you set it up, and put - in front of (?-s) when you turn it off.)

Therefore, the regular expression compilation code = re.compile("(?s)/\*.*?\*/") is code = re.compile("/\*.*"?\*/", java.util.regex.Pattern.DOTALL).

Note: http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#DOTALL


2022-09-22 21:59

Can you tell me the background? I've never seen it before. I've seen the (?P<name>regex) combination of parentheses and question marks.


2022-09-22 21:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.