-1

I want to match any character after some word (limit is an example).

✔ nnn : am
-limitaaaa
ça UNICODE HERE
sdasdsadaw
✔ UNICODE HERE
limitaaaa,.@#!~`%$&*()[]{}|\+=-_?/'":;.><,
777723xx sss fff s :,

my current regex. https://regex101.com/r/bSbUBG/2

/limit+([.*\s\w\d\p{M}\p{L}\p{S},:@#!~`%$&()\[\]\{\}\|\\+=\-_\?\/\'";><]+)/

My regex works, but it looks too long. My question is can I make it shorter?

Note: If you need to know what kind of language that I used, I using PHP for this.

revo
  • 47,783
  • 14
  • 74
  • 117
plonknimbuzz
  • 2,594
  • 2
  • 19
  • 31
  • Maybe `(?s)limit(.+)`? In PHP, `'~limit(.+)~s'` ([demo](https://regex101.com/r/R107iF/2))? Looks like you want to match any 1 or more chars after `limit`. – Wiktor Stribiżew Feb 04 '19 at 11:42
  • You could use [`limit+([\s\S]+)`](https://regex101.com/r/bSbUBG/3), which is basically every character including newlines. You could also write `limit(.+)` in `DOTALL` mode. – Jan Feb 04 '19 at 11:42
  • WTF. i really try that before. but i'm sure thats was not work. but thats working. miracle. @Jan Can u post it as an answer? i will check it – plonknimbuzz Feb 04 '19 at 11:45
  • So all you missed was an `s` modifier. – Wiktor Stribiżew Feb 04 '19 at 11:47
  • @WiktorStribiżew i think i dont need that. Thank you for your suggestion. I appreciate that – plonknimbuzz Feb 04 '19 at 11:49
  • No need for a workaround like `[\s\S]`, PCRE has `s` modifier support, and you do need it more than `[\s\S]`. Even if you have a longer pattern and this is part of it, all you need is `limit((?s:.+))`. Do not use `[\s\S]` if you are using PCRE. – Wiktor Stribiżew Feb 04 '19 at 11:50
  • @WiktorStribiżew thats works. with `s` modifier. https://regex101.com/r/bSbUBG/6 You both are awesome. – plonknimbuzz Feb 04 '19 at 11:51
  • Do you want to match word also (limit in your example)? Or only what is after it? – virolino Feb 04 '19 at 11:52
  • @virolino no. I can make it by myself, i just want to know how to make it short, but Wiktor and Jan give me the answer. thanks bro – plonknimbuzz Feb 04 '19 at 11:54

1 Answers1

0

You could either use

limit([\s\S]+)

Or

limit(.+)

in DOTALL mode (s flag).

See a demo on regex101.com or this one for the latter.

Jan
  • 42,290
  • 8
  • 54
  • 79