Author Topic: don't use any part of the match in the next match  (Read 36 times)

0 Members and 1 Guest are viewing this topic.

Offline brianlangeTopic starter

  • Enthusiast
  • Posts: 228
    • View Profile
don't use any part of the match in the next match
« on: Yesterday at 08:26:00 PM »
Here's my text:

%%match1%% some text %% match2 %% some more text %%match3%%

I want to write an expression like /%%[\w]+%%/
but this will result in a match for %% some text %%
I want to to ignore an character from the previous match.

thanks in advance.

Offline abareplace

  • Irregular
  • Posts: 14
    • View Profile
    • Aba Search and Replace
Re: don't use any part of the match in the next match
« Reply #1 on: Yesterday at 08:32:30 PM »
Hello, Brian,

in most tools, it will not match %%some text%%, because %% is already included in the first match. For example, in PHP:

Code: [Select]
<?php

echo preg_replace('/%%(.+?)%%/''[$1]''%%match1%% some text %% match2 %% some more text %%match3%%')

?>


Output:

Code: [Select]
[match1] some text [ match2 ] some more text [match3]

So, you don't have to worry :)
« Last Edit: Yesterday at 08:33:41 PM by abareplace »

Offline brianlangeTopic starter

  • Enthusiast
  • Posts: 228
    • View Profile
Re: don't use any part of the match in the next match
« Reply #2 on: Yesterday at 08:46:38 PM »
Thanks!

Offline AyKay47

  • Addict
  • Posts: 2,245
  • Gender: Male
  • God Bless
    • View Profile
Re: don't use any part of the match in the next match
« Reply #3 on: Yesterday at 09:44:38 PM »
do you care whether or not the regex omits spaces?
RegEx Nerd
There will be a time when I will truncate all tables, and set it free.