.NET Framework Bookmark and Share   
 index > Regular Expressions > How to append text to a string using regular expressions in find and replace
 

How to append text to a string using regular expressions in find and replace

Hi, need to add a string to the end of a series of urls in a .mrk file (basically, like txt, but for library records). I need to replace/etext/16808 with /etext/16808.html?default where 16808 is any given integer.

The program I am using, MarcEdit, offers a find and replace function that uses regular expressions. So far, I've found a find expression that works. Requesting /etext/\d* will find all of the occurrences that I need to replace, but I cannot figure out the right replace expression to add the .html?default string without deleting the string that I used to find it.

Any suggestions would be much appreciated.

Thanks,
Juli
Anjuli
I'm not familar with MarcEdit however if you had a regex such as the following:
(/etext/\d+)
Then you could use a replace string that uses a backreference to do what you're looking for:
${1}.html?default

Again the syntax for backreferences in MarcEdit might be custom but give this a try.
Jerry Schulist

Please remember to mark replies which answer your question as answers and vote for replies which are helpful.
  • Edited byinetscan Thursday, September 03, 2009 9:49 PMtypo
  •  
inetscan

try something like this:

Find --> (\/etext\/\d+)

Replace --> \1\.html

Regular Expressions come in many different flavors. If the version you are working with can use named captures, you can even do this:

Find --> (?<Url>\/etext\/\d+)
Replace --> ${Url}\.html

Read the documentation on the Regex that your Editor supports.


John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
  • Edited byJohnGrove Thursday, September 03, 2009 4:38 PM
  •  
JohnGrove
I use UltraEdit, and the Regex that uses really is terrible. I am thinking about getting EditPro.
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
JohnGrove
True, UltraEdit is very ultra.
It supports mostRegex, but not by default.
I remeber I ever had to check a box in a hidden place, "use Perl compatible syntax" for Regex,
or it adopts a very strange syntax of its own.

But the replacement is very terrible, over-functioned.
it will replace everthing in the specified folder, even images and other binary file.
And I have to find to check another (deep)box to define the file types.
Then it's OK.

Ultra Edit is very powerful, ultra powerful, but it's too complex,
and not easy to use now. The default setting is not good.
www.wonderstudio.cn
Eping Wang
It supports some weird flavor of Regex that is analagous to the Like Operator. I don't like it at all. But the Editor as such is decent.
John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
JohnGrove

"weird", what a exact word!
"decent" is also proper.
I learned two English words, thanks.


www.wonderstudio.cn
Eping Wang

You speak very good English Eping


John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
JohnGrove

You can use google to search for other answers

Custom Search

More Threads

• How to read Hierarchial text in string
• Regular Expression Help
• Get the string value between given indexes..
• split address to multiple strings
• Regex / string processing
• regular expression for date in the given format
• Problem With Whole Words
• Strip HTML and Scripts
• Regular Expression for password
• RegEx with Text File