Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use RegEx flags in PhpStorm's "Find and Replace"?

Tags:

regex

phpstorm

When searching with a regex I want .* to match line separators (\n). To do it you should add s flag, but I can't quite figure out how to do it. Is there a way to add regex flags in PhpStorm?

like image 321
Boykodev Avatar asked Jan 29 '23 23:01

Boykodev


1 Answers

Use a DOTALL inline modifier option:

(?s).*
^^^^

This pattern means that all . to the right of the (?s) will also match line break chars.

Inline Modifier (?s)
In .NET, PCRE (C, PHP, R…), Perl, Python and Java (but not Ruby), you can use the inline modifier (?s), for instance in (?s)BEGIN .*? END. See the section on inline modifiers for juicy details about three additional features (unavailable in Python): turning it on in mid-string, turning it off with (?-s), or applying it only to the content of a non-capture group with (?s:foo)

like image 109
Wiktor Stribiżew Avatar answered Jan 31 '23 11:01

Wiktor Stribiżew