Nico Müller
Nico Müller

Reputation: 1874

regex first occurance in whole text only

I searched through a lot of "regex first match only" questions but couldn't manage to build my regex based on the results. I am not good in regex, i use the following to replace all the occurrences in the text in perl:

$xmlText =~ s/(xmlns)/$exhangeText/g;

However I just want to have the first occurrence to be changed, how can I achieve this?

Many thanks for any help Nico

Upvotes: 1

Views: 108

Answers (1)

Toto
Toto

Reputation: 91430

Just remove the global modifier:

$xmlText =~ s/(xmlns)/$exhangeText/;

Upvotes: 5

Related Questions