Two Laptop Bag*
The moose likes Linux / UNIX and the fly likes Search and replace tip Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Search and replace tip" Watch "Search and replace tip" New topic
Author

Search and replace tip

Nicolas Viollin
Greenhorn

Joined: Apr 13, 2001
Posts: 6
Hi there !

I've got many string like this 'xxxxyyyzzz'. 'xxxx' and 'zzz' are fixed part of the string, they're always the same.

I would like to replace that 'xxxxyyyzzz' string with this 'xxxxyyyzzzwwww' string.

How do i tell the S&R to keep the mobile part of my string and simply add the 'wwww' part ?

to be clear, here are exemples:


'Mike125NAT' where 'Mike' is 'xxxx', '125' is 'yyy' and 'NAT' is 'zzz' would become 'Mike125NATFive'
'James007Bond' where 'James' is 'xxxx', '007' is 'yyy' and 'Bond' is 'zzz' would become 'James007BondLicencedtokill'

thanks for your help !
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923



Is the variable-part allways 3 characters long, then use ... instead of .*, is it allways made of digits, use [0-9]*, is it something, except a blank, use [^ ]* .

May there be multiple replacements in a row, use 'g' for global as postfix-operator:



http://home.arcor.de/hirnstrom/bewerbung
Nicolas Viollin
Greenhorn

Joined: Apr 13, 2001
Posts: 6
thanks a lot, works perfectly !
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Search and replace tip
 
Similar Threads
Response time never exceeding 5 seconds requirement in part II
JtreeTable- displaying nodes of a tree in diff. columns of table
overriding
Problem with SQL uqery or DSN
intRange validations