/    Sign up×
Community /Pin to ProfileBookmark

understanding the b a bit more well

Hey guys , i have been trying to work on my regex skills a bit , just had a small hiccup when i was trying to understand the followng regex outcome:

[CODE]
‘hello ! h’.match(/b/g)
[/CODE]

What i ofcoutse got was:

[CODE]
[“”, “”, “”, “”]
[/CODE]

now what exactly are those 4 matches ??

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KeverJun 16.2016 — Boundaries are at the start of a string, end of a string and between each word and non-word character.

'bhellob ! bhb'
Copy linkTweet thisAlerts:
@gautamz07authorJun 16.2016 — ohh , makes it a bit more clear , just need a bit more clarity:

see below regex:

"hello ! hi mi".match(/b/g)

I get six matchs:

["", "", "", "", "", ""]

Now small modification .. lets add a ! to the tail .

"hello ! hi mi ! ".match(/b/g)

still i get:

["", "", "", "", "", ""]

So why is it that the space after ! is not being matched ?

Thank you.
Copy linkTweet thisAlerts:
@KeverJun 16.2016 — Sorry, my explanation was a little to short.

Boundaries are at the start of a string (when the string start with a word character) or end of a string (when the string ends with a word character) and between each word and non-word character.

Word charachters are [A-Za-z0-9_]. The space is a non-word character.
×

Success!

Help @gautamz07 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...