List Info

Thread: find and replace




find and replace
country flaguser name
United States
2007-09-17 12:06:21
I have a situation where I want to find a specific word in a
string,
say the second word, and append an "x" to the
beginning of that word.
It won't always be the second word so I would like to be
able to
supply the word number.

I'm working in VBScript.

Thanks for your help.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: find and replace
country flaguser name
United States
2007-09-18 01:04:08
maybe something like this:

regex = "((?:[^s]*s))"
replace = "$1x"

If you want to change the 10th word, you can change  by

(10-1).

More info:
http://java.sun.com/docs/books/tutorial/essent
ial/regex/index.html
http://java.sun.com/docs/books/tuto
rial/essential/regex/pre_char_classes.html

HTH,
DAvid

On Sep 17, 7:06 pm, SteveH <steve.ho...gmail.com> wrote:
> I have a situation where I want to find a specific word
in a string,
> say the second word, and append an "x" to the
beginning of that word.
> It won't always be the second word so I would like to
be able to
> supply the word number.
>
> I'm working in VBScript.
>
> Thanks for your help.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: find and replace
country flaguser name
United States
2007-09-18 09:40:57
When I run this using the input string "one two"
the results I get
are:

regex = "((?:[^s]*s))"
replace = "$1x"
replace result "one xtwo x"
desired result "xone two"


regex = "((?:[^s]*s))"
replace = "$1x"
replace result "two x"
desired result "one xtwo"

I am trying to parse your regex but I'm afraid I am too much
of a
novice.  Could you break it down a piece at a time?

Thanks.



On Sep 18, 12:04 am, David  Portabella
<david.portabe...gmail.com>
wrote:
> maybe something like this:
>
> regex = "((?:[^s]*s))"
> replace = "$1x"
>
> If you want to change the 10th word, you can change 
by 
> (10-1).
>
> More info:http://java.sun.com/docs/books/tut
orial/essential/regex/index.htmlhttp://java.sun.com/docs/boo
ks/tutorial/essential/regex/pre_char_clas...
>
> HTH,
> DAvid
>
> On Sep 17, 7:06 pm, SteveH <steve.ho...gmail.com> wrote:
>
>
>
> > I have a situation where I want to find a specific
word in a string,
> > say the second word, and append an "x"
to the beginning of that word.
> > It won't always be the second word so I would like
to be able to
> > supply the word number.
>
> > I'm working in VBScript.
>
> > Thanks for your help.- Hide quoted text -
>
> - Show quoted text -


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: find and replace
country flaguser name
United States
2007-09-19 16:43:52
regex="((?:[^s]*s))(.*)"
replace="$1x$2"

If you want to change the 3rd word, you can change  by
  (3-1).
that is, remember to substract 1.

breaking it down:

s     a space character.
[^s]  anthing but a space character
[^s]* a set of continuous non-spaces characters
(xxx)  it will capture a group. so, $1 will reference this
group.
(?xx)
it does not capture the group
(xxx) the group xxx must be repeated 5 times.
.*     any sequence


A good short/quick tutorial is here:
http://java.sun.com/docs/books/tutorial/essent
ial/regex/index.html

HTH,
DAvid


On Sep 18, 4:40 pm, SteveH <steve.ho...gmail.com> wrote:
> When I run this using the input string "one
two" the results I get
> are:
>
> regex = "((?:[^s]*s))"
> replace = "$1x"
> replace result "one xtwo x"
> desired result "xone two"
>
> regex = "((?:[^s]*s))"
> replace = "$1x"
> replace result "two x"
> desired result "one xtwo"
>
> I am trying to parse your regex but I'm afraid I am too
much of a
> novice.  Could you break it down a piece at a time?
>
> Thanks.
>
> On Sep 18, 12:04 am, David  Portabella
<david.portabe...gmail.com>
> wrote:
>
> > maybe something like this:
>
> > regex = "((?:[^s]*s))"
> > replace = "$1x"
>
> > If you want to change the 10th word, you can
change  by 
> > (10-1).
>
> > More info:http://java.sun.com/docs/books/tutori
al/essential/regex/index.htmlhtt......
>
> > HTH,
> > DAvid
>
> > On Sep 17, 7:06 pm, SteveH <steve.ho...gmail.com> wrote:
>
> > > I have a situation where I want to find a
specific word in a string,
> > > say the second word, and append an
"x" to the beginning of that word.
> > > It won't always be the second word so I would
like to be able to
> > > supply the word number.
>
> > > I'm working in VBScript.
>
> > > Thanks for your help.- Hide quoted text -
>
> > - Show quoted text -


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )