Regular Expression to replace part of a string

flyersun

I need to replace part of a string, it's dynamically generated so I'm never going to know what the string is.

Here's an example "session12_2" I need to replace the 2 at the end with a variable. The "session" text will always be the same but the number will change.

I've tried a standard replace but that didn't work (I didn't think it would).

Here's what I tried:

col1 = col1.replace('_'+oldnumber+'"', '_'+rowparts[2]+'"');

Edit: I'm looking for a reg ex that will replace '_'+oldnumber when it's found as part of a string.

André Ferrari

If you will always have the "_" (underscore) as a divider you can do this:

 str = str.split("_")[0]+"_"+rowparts[x];

This way you split the string using the underscore and then complete it with what you like, no regex needed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Replace part of the String by Regular Expression

From Dev

Regular expression to replace a string

From Dev

Regular expression for getting part of string

From Dev

Regular expression to retain part of the string

From Dev

Replace query string with regular expression?

From Dev

Multiple string replace with a Regular Expression

From Dev

php regular expression string replace

From Dev

Java String replace Regular Expression

From Dev

Regular Expression: replace string in javascript

From Dev

Replace word in string, regular expression

From Dev

Replace string using Regular expression

From Dev

Notepad++ regular expression - replace a part of regex

From Dev

C# Regular Expression and Replace on part of the match

From Dev

Regular Expression to match part or all of a string

From Dev

Exclude part of string using Regular expression

From Dev

Extracting a specific part of a string with regular expression in Python

From Dev

Regular expression - Get specific part of string

From Dev

mask part of a string using regular expression

From Dev

How to capture a String expression and replace only a part of it?

From Dev

How to capture a String expression and replace only a part of it?

From Java

Python string.replace regular expression

From Dev

Regular Expression to Replace All But One Character In String

From Dev

How to replace a string in a regular expression match

From Dev

Find regular expression string and replace it in R

From Dev

Regular Expression - detect Specific Url and replace that string

From Dev

Regular expression Replace to remove numbers in prefix to the string

From Dev

replace String with another in java using regular Expression

From Dev

Replace string with regular expression and my own parameter

From Dev

replace a string in all occurence using regular expression

Related Related

  1. 1

    Replace part of the String by Regular Expression

  2. 2

    Regular expression to replace a string

  3. 3

    Regular expression for getting part of string

  4. 4

    Regular expression to retain part of the string

  5. 5

    Replace query string with regular expression?

  6. 6

    Multiple string replace with a Regular Expression

  7. 7

    php regular expression string replace

  8. 8

    Java String replace Regular Expression

  9. 9

    Regular Expression: replace string in javascript

  10. 10

    Replace word in string, regular expression

  11. 11

    Replace string using Regular expression

  12. 12

    Notepad++ regular expression - replace a part of regex

  13. 13

    C# Regular Expression and Replace on part of the match

  14. 14

    Regular Expression to match part or all of a string

  15. 15

    Exclude part of string using Regular expression

  16. 16

    Extracting a specific part of a string with regular expression in Python

  17. 17

    Regular expression - Get specific part of string

  18. 18

    mask part of a string using regular expression

  19. 19

    How to capture a String expression and replace only a part of it?

  20. 20

    How to capture a String expression and replace only a part of it?

  21. 21

    Python string.replace regular expression

  22. 22

    Regular Expression to Replace All But One Character In String

  23. 23

    How to replace a string in a regular expression match

  24. 24

    Find regular expression string and replace it in R

  25. 25

    Regular Expression - detect Specific Url and replace that string

  26. 26

    Regular expression Replace to remove numbers in prefix to the string

  27. 27

    replace String with another in java using regular Expression

  28. 28

    Replace string with regular expression and my own parameter

  29. 29

    replace a string in all occurence using regular expression

HotTag

Archive