0

I have a following regex:

[.][a-zA-Z]

So, if there's a string like .row then it will select .r. What I want is to be able to select only the dot i.e. regex selects only the dot(.)!

3
  • Did you try lookahead? Commented Feb 12, 2019 at 5:59
  • What's that? Anyway, let me check Commented Feb 12, 2019 at 6:00
  • Without more details: what part of capture group 2 in ((\.)][a-zA-Z]+) does not address this need? And more importantly, what are you actually trying to do, because just "finding the dot" in something like .row cannot possibly be the end of what you want to do. What are you trying to do that requires finding that dot? Commented Feb 12, 2019 at 6:07

2 Answers 2

2

You need to use positive lookahead

let str  = `.row`

console.log(str.match(/\.(?=[A-Za-z])/g))

Sign up to request clarification or add additional context in comments.

4 Comments

@Sanjay sorry it was a typo. fixed
I tried this([\.][(?=[A-Za-z])]/g) in VSCode find and replace. It didn't work
@Sanjay why are you putting positive lookahead in character class. use this /\.(?=[A-Za-z])/
Can you help me with this: stackoverflow.com/questions/54644846/…?
0

If you want to just select the dot, escape your . with \. since . means any single character. And don't include [a-zA-Z]

[\.]

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

2 Comments

It will select the number too then
What number?? Please at least try to give us your input and expected output.

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.