[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Regex
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 14
Thread images: 4
File: email.jpg (31 KB, 600x500) Image search: [Google]
email.jpg
31 KB, 600x500
In JavaScript RegExp how to return what is match so far.

For example:

"123567890".match(/1234567890/i) returns "123"
"abcede".match(/abcdef/i) return "abc"

In another word return what is matched so far and disregarding the rest even if the whole regexp doesn't match.
>>
>>54929162
it returns an array and it ony returns one item in the array since you have ony one match
>>
>>54929289
Close but not quite. Look at the examples again.
The flag might be wrong, but you'll get the idea.

Even if the whole regexp doesn't match it should still return what is matched so far starting from the left once it stop matching.

So "abcedeabc".match(/abcde/i) will only return "abc" because that is what it was matched so far.
>>
>>54930035
it returns null to me in chromium
>>
>>54930177
That is not a concrete example. That is what I intending for it to do.
>>
>>54930212
then use expressions which match multiple letters

abc.+ for example
>>
You can't just stop matching half way, regular expressions either have a match or not.
>>
>>54930212
Try searching for "partial match"
>>
>>54930254
also, you could capture the difference (if you need it)
>>
>>54929162
"123567890".match(/1234567890|123456789|12345678|1234567|123456|12345|1234|123|12|1/i) returns "123"
"abcede".match(/abcdef|abcde|abcd|abc|ab|a/i) returns "abc"
>>
>>54930342
you could even write a function to generate that
>>
>>54930261
That might be what I was looking for, but it looks like regex might not be able to do it as my regex is more complex than the example that was given so as what I also trying to match.
>>
>>54932329
My regex is very dynamic not static also the same for input or string that I'm trying to match.
>>
>>54932363
I guess the only to do this is to make each sub regex of the whole regex optional and then go from there.
Thread replies: 14
Thread images: 4

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.