Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable whitespace insensitive mode of regular expression in PHP?

Tags:

regex

php

I've tried "m" modifier,but not working:

$reg = '/...
        /m';

preg_match($reg,...,$match);

EDIT

Or maybe I need a modifier that can ignore white space like ENTER,TAB and so on. Because when I remove the white space in my regex it works.

EDIT AGAIN:

I need a modifier so that regular expression

"/aaaa b/",
"/aaaa
 b/"

are the same thing,say,it just ignores the white space in regex itself.

like image 933
omg Avatar asked Sep 16 '09 06:09

omg


People also ask

How do I get rid of white space in regex?

The replaceAll() method accepts a string and a regular expression replaces the matched characters with the given string. To remove all the white spaces from an input string, invoke the replaceAll() method on it bypassing the above mentioned regular expression and an empty string as inputs.

Which modifier ignores white space in regex?

Turn on free-spacing mode to ignore whitespace between regex tokens and allow # comments. Turn on free-spacing mode to ignore whitespace between regex tokens and allow # comments, both inside and outside character classes.

Does regex include whitespace?

Yes, the dot regex matches whitespace characters when using Python's re module.


1 Answers

The modifier you need is x

print_r(preg_match('/aaa
        bbb/x', 'aaabbb'));
like image 193
too much php Avatar answered Sep 19 '22 08:09

too much php