Axel
Axel

Reputation: 5141

Regex to match the string which contains dot

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(.)!

Upvotes: 0

Views: 4636

Answers (2)

Code Maniac
Code Maniac

Reputation: 37775

You need to use positive lookahead

let str  = `.row`

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

Upvotes: 2

Solomon Tam
Solomon Tam

Reputation: 739

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/

Upvotes: 0

Related Questions