Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  11] [ 6]  / answers: 1 / hits: 27561  / 13 Years ago, tue, january 24, 2012, 12:00:00

please consider the following javascript code:



myObject.myMethod();.replace(/.w+(/g, xxx);


it gives myObjectxxx); as .myMethod( is selected.



Now I would only select myMethod instead. In other words I want to select any word starting with . and ending with ( (excluded).



Thanks, Luca.


More From » regex

 Answers
36

General answer: Capture the part that you want to keep with parentheses, and include it in the substitution string as $1.



See any regexp substitution tutorial for details.



Here: just include the . and the ( in your substitution string.



For an exercise, write a regexp that will turn any string of the scheme --ABC--DEF-- to --DEF--ABC-- for arbitrary letter-values of ABC and DEF. So --XY--IJK-- should turn into --IJK--XY--. Here you really need to use capture groups and back references.


[#87823] Monday, January 23, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mustafaericho

Total Points: 322
Total Questions: 103
Total Answers: 110

Location: Montenegro
Member since Thu, Jun 16, 2022
2 Years ago
mustafaericho questions
Mon, May 31, 21, 00:00, 3 Years ago
Sun, May 23, 21, 00:00, 3 Years ago
Sat, Feb 13, 21, 00:00, 3 Years ago
Sat, Jan 2, 21, 00:00, 3 Years ago
Thu, Nov 12, 20, 00:00, 4 Years ago
;