Is there anything (punctuation, perhaps? placement with other words and terms?) that will consistently distinguish a name from any other proper noun in your text? For example, how can your script consistently distinguish between "Ibrahim Ali Muhammad" and "Grand Trunk Road" and "Pushtoon Garhi Pabbi", since all use the same capitalization scheme? You might have to define some more complicated criteria for recognizing names. Or will names only be in the headings of each entry, i.e. toward the beginning?
In general, you would want:
$line =~ s{($regexp)}{<name>$1</name>}g;The 'g' flag may or may not be needed, depending on what you're doing. If there's more than one name in a line, that would catch it. If there's only one name, you don't need it. The parentheses () match the name in your line and place it in $1, so you can put the tags around it in your replacement expression. Using curly brackets {} instead of / to mark your regexp avoids having to escape your slashes ("leaning toothpick syndrome," I think someone called it -- it can get confusing!). Any other characters could be used to delimit your regexp if you'd prefer. What I have above is equivalent to this:
$line =~ s/($regexp)/<name>$1<\/name>/g;In reply to Re^3: Fine tuning a reg exp
by LonelyPilgrim
in thread Fine tuning a reg exp
by markjrouse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |