Page 1 of 1

How to find variable length words...

Posted: Thu Jan 21, 2010 3:25 pm
by frich96
Hi,

I'm sure this has been covered somewhere before... but my searches didn't give any useful results.

I am trying to edit a collection of XML documents that have variable length words that I want to replace with the same word;

words are formatted as: "User-#", or...
"User-##", or...
"User-###"

where "#" is an integer number from 0-9.

All words are (planned) to be replaced with "User-2".

Each method I've tried leaves me with a new word that that is made of the replacement word + all the original #'s from the original word.

Can anyone help?

Thanks,
Fred

SOLVED - How to find variable length words...

Posted: Thu Jan 21, 2010 3:58 pm
by frich96
OK.

I think I've found, at least a work around if not the best answer. Due to the fact that my data is fairly homogeneous, I can submit the following FINDs in this order...

1. Find "User-[0-9][0-9][0-9]" --> execute
2. Find "User-[0-9][0-9]" --> execute
3. Find "User-[0-9]" --> execute

Of course, with runs 2 and 3, I'm actually re-editing previous edits, but it ends with the intended replaced text in all files.

*Still interested if there's a better way (single pass?) to do this.*

Thanks,
Fred

Posted: Thu Jan 21, 2010 5:10 pm
by ben_josephs
User-[0-9]+ for any non-zero number of digits
or
User-[0-9]{1,3} for 1, 2 or 3 digits

In WildEdit (but not in TextPad) you can use \d for [0-9].