Hi,
I want to thank you so much for making so a great product. It is really a lifesaver.
I am interested in finding only the first occurrence of a string in multi line page. Is there a way to do this? Thank you for your time.
Find First occurrence of a string in multi line page
-
- Posts: 4
- Joined: Mon Apr 16, 2012 3:39 pm
- DigitalVolcano
- Site Admin
- Posts: 1863
- Joined: Thu Jun 09, 2011 10:04 am
Re: Find First occurrence of a string in multi line page
I think this should do it:
(?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)
this will match the first occurance of 'myphrase' in the file
Note, you need the 'Dot matches newline' option turned on, otherwise it will match the first occurance in each line.
(?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)
this will match the first occurance of 'myphrase' in the file
Note, you need the 'Dot matches newline' option turned on, otherwise it will match the first occurance in each line.
-
- Posts: 4
- Joined: Mon Apr 16, 2012 3:39 pm
Re: Find First occurrence of a string in multi line page
Thank you so much for you quick reply.
You saved me a lot of time.
You saved me a lot of time.
Last edited by computer_guy on Wed Jun 13, 2012 8:04 pm, edited 1 time in total.
-
- Posts: 4
- Joined: Mon Apr 16, 2012 3:39 pm
Find 2nd, 3rd,4th occurrence of a string in multi line page
While we are discussing this topic, I was wondering if there was a way to find a particular occurrence of a string (eg. 2nd, 3rd,4th or last)in a multi line file?
Any help is really appreciated.
Any help is really appreciated.
Re: Find First occurrence of a string in multi line page
I think it would be something like this:
((?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)){3}(?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)
This would match all the text up to and including the next occurrence after the first 3 of them, so the fourth match. Depending on if you want to process (change) this text, or only catch it, you may use the short form
((?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)){4}
to just find this single long match, or
replace
(((?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)){3}(?<!.*?\bmyphrase\b.*?))(\bmyphrase\b)
by either
$1
to remove the fourth match
or
$2
to remove all the text up to the fourth match.
((?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)){3}(?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)
This would match all the text up to and including the next occurrence after the first 3 of them, so the fourth match. Depending on if you want to process (change) this text, or only catch it, you may use the short form
((?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)){4}
to just find this single long match, or
replace
(((?<!.*?\bmyphrase\b.*?)(\bmyphrase\b)){3}(?<!.*?\bmyphrase\b.*?))(\bmyphrase\b)
by either
$1
to remove the fourth match
or
$2
to remove all the text up to the fourth match.
-
- Posts: 1
- Joined: Thu Nov 08, 2012 6:56 am
Re: Find First occurrence of a string in multi line page
@DigitalVolcano thanks .. it work for me
-
- Posts: 2
- Joined: Fri Nov 22, 2013 5:47 am
Re: Find First occurrence of a string in multi line page
I was also searching for a way to find the first occurrence of a string in multi line page for a project I am doing. Thanks to DigitalVolcano. The solution was very easy and helpful to solve the issue. It really helped me out.
Thanks
Lourene
Schools in Oman
Thanks
Lourene
Schools in Oman