Jump to content

[SOLVED] Optional Regex


jackpf

Recommended Posts

Good evening,

I was just wondering how to make part of the regex optional. For example, this is my current regex:

'/\[text width\=(.*?) height\=(.*?)\](.*?)\[\/text\]/isS'

However, I'd like to make the width=(.*?) height=(.*?) optional.

 

I've tried

'/\[text( width\=(.*?))?( height\=(.*?))?\](.*?)\[\/text\]/isS'

However, since my replacement is

'<textarea style="overflow: auto;" cols="$1" rows="$2">$3</textarea>'

If the height and width are ommited, it sets the contents as $1, so so it messes up my numbering.

 

So yeah...anyone have any ideas? :)

 

Thanks, Jack.

Link to comment
https://forums.phpfreaks.com/topic/157139-solved-optional-regex/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.