0

I Want to Find string ,whose last character may or may not present

"abc,efg,ASD"
"abc,ASD,efg"

so, i have to find ASD with or without " , "

3
  • str.match(/\bASD\b/g)? Commented May 28, 2016 at 17:14
  • Are you looking for an exact match on an element of a comma-separated list? For example, "abc,efg,ASD" or "abc,ASD,efg" should match (looking for ASD) but "abc,efg,ASDF" or "abc,ASDF,efg" should not? Commented May 28, 2016 at 17:21
  • I read it as if you needed ASD from the first string, and ASD, from the second. The criteria are not clear: get all non-word chars after ASD but whitespace (/\bASD[^\w\s]*/)? Or an optional comma (/\bASD,?/)? Commented May 28, 2016 at 20:50

2 Answers 2

2

Description

[,"](ASD)[,"]

Regular expression visualization

This regular expression will do the following:

  • match the asd between commas or comma and quote,
  • place the value into capture group 1

Example

Live Demo

https://regex101.com/r/mV9vA9/1

Explanation

NODE                     EXPLANATION
----------------------------------------------------------------------
  [,"]                     any character of: ',', '"'
----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    ASD                      'ASD'
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
  [,"]                     any character of: ',', '"'
----------------------------------------------------------------------
Sign up to request clarification or add additional context in comments.

Comments

0

Does this answer your question?

var regex = /,ASD,?/g;
var result = regex.exec("abc,ASD\nabc,ASD,dsa");
console.log(result);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.