Simple regex question

  • Thread starter Thread starter MaxMax
  • Start date Start date
M

MaxMax

I want to add a text to another text using regular expressions... An example

before= "foo"
after= "foobar"

before= "one"
after= "onebar"

before = ""
after = "bar"

How should I do? I found 2 nearly correct patterns:

search = ".*", replace = "$&bar"

but this will give me: foobarbar, onebarbar, bar

search = ".+", replace = "$&bar"

but this will give me: foobar, onebar, ""

Can anyone help me?

Thanks!
 
MaxMax said:
I want to add a text to another text using regular expressions... An
example
before= "foo"
after= "foobar"

before= "one"
after= "onebar"

before = ""
after = "bar"

...

The following solution works for all your examples:

after = before + "bar";

So if you really need to use regular expressions, there must be something
you haven't told us.

Ebbe
 
Hi,

I agree with Ebbe that your simple task can be achieved through String
class "+" operator. Does it meet your need? Can you tell me why do you want
to use Regex for this task?

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I agree with Ebbe that your simple task can be achieved through String
class "+" operator. Does it meet your need? Can you tell me why do you
want
to use Regex for this task?
I have already found the solution. $.*^ and $&bar
The + operator idea was VERY stupid. Clearly if I simply wanted to use the +
operator and the standard String methods I would have used the standard
String methods. I want to use the regex so I can have them in a separate
user-alterable file (I have a text and a program that analyze the text. The
user can input regexs to "patch" the text before/after the analysis)

--- bye
 
Hi,

Thank you for sharing the background reason. Yes, if your text resides in a
separate file, you may use Regex to match/search them and add your
customized string to it.

If you need further help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top