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
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.
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
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.
© 2024 OneMinuteCode. All rights reserved.