namlunthkl

StringRegExpReplace - Problem - Please help!!!

10 posts in this topic

I'm having a string:

$str='<q1="1234"><q2="3452">'

I want to Replace string between <ql=" and ">

And here is my Script:

$str='<q1="1234"><q2="3452">'
$output = StringRegExpReplace($str, '(<q1=")(.*)(">)', '${1}907605$3')
ConsoleWrite($output)

But it only returns:

<q1="907605">

But what I want is:

<q1="907605"><q2="907605">


Help me please. :(:( 

Share this post


Link to post
Share on other sites



Please... I need it now :(:( :doh:

Share this post


Link to post
Share on other sites

UPUP......... Please help!!!

Share this post


Link to post
Share on other sites
$output = StringRegExpReplace($str, '<q\d+="(\d*)">', '907605')

@namlunthkl: There're no need to bump the thread. There're many members but nobody can stay all the times in the forum to answer all the question. Just wait politely.

1 hour ago, namlunthkl said:

But what I want is:

<q1="907605"><q2="907605">

 

If you want replace all the value to a single value, it's easy but you need the right regex pattern

$output = StringRegExpReplace($str, '<q\d+="(\d*)">', '907605')
1 person likes this

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites
Just now, binhnx said:
$output = StringRegExpReplace($str, '<q\d+="(\d*)">', '907605')

@namlunthkl: There're no need to bump the thread. There're many members but nobody can stay all the times in the forum to answer all the question. Just wait politely.

If you want replace all the value to a single value, it's easy but you need the right regex pattern

$output = StringRegExpReplace($str, '<q\d+="(\d*)">', '907605')

big thanks!!!!!!

Share this post


Link to post
Share on other sites

@binhnx Sorry but your script doesn't work :(

Share this post


Link to post
Share on other sites

@binhnx It only return: 907605907605

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Sorry, I misunderstood about StringRegExpReplace

$output = StringRegExpReplace($str, '(<q\d+=")\d*(">)', '${1}907605${2}')

 

Edited by binhnx
Formatted code

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites
1 minute ago, binhnx said:

Sorry, I misunderstand about StringRegExpReplace


$output = StringRegExpReplace($str, '(<q\d+=")\d*(">)', '${1}907605${2}')

@binhnx Please message with me

Share this post


Link to post
Share on other sites
StringRegExpReplace($str, '(<q\d+=")(.*?)(">)', '${1}907605$3') ; note the "?" after ".*" (look at the StringRegExp help page)

or

StringRegExpReplace($str, '<q\d+="\K[^"]+(?=")', '907605')

 

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now