admin管理员组文章数量:1265381
I need a Regular Expression that matches everything after the first two characters in a string.
For Example (original string listed first, then what I'd like to match):
AZ0bc1234 > 0bc1234
50def123 > def123
!@hijk1234 > hijk1234
All that matters is position, any characters (alpha-numeric with symbols) could be included in the original string.
I've tried many things, but everything I attempt matches at least one of the first two characters. The closest I've e is using \B.*
to match everything but the first character.
I need a Regular Expression that matches everything after the first two characters in a string.
For Example (original string listed first, then what I'd like to match):
AZ0bc1234 > 0bc1234
50def123 > def123
!@hijk1234 > hijk1234
All that matters is position, any characters (alpha-numeric with symbols) could be included in the original string.
I've tried many things, but everything I attempt matches at least one of the first two characters. The closest I've e is using \B.*
to match everything but the first character.
- I'll have a proper look at it, but in the meantime you might find this link useful www.regexlib. – CHill60 Commented Jan 14, 2013 at 16:39
-
What language are you using? Are you sure you need to use a regex? If you're using PHP, for example, you could use the
substr()
function. – Andy Lester Commented Jan 14, 2013 at 16:39 - I understand there are easier ways of doing this, but I'm curious if it's theoretically possible using regular expressions exclusively. – Matt K Commented Jan 14, 2013 at 16:41
- you need to specify the language you are using – Anirudha Commented Jan 14, 2013 at 16:44
- I'm attempting this in JavaScript. – Matt K Commented Jan 14, 2013 at 16:45
3 Answers
Reset to default 7You were looking for a positive lookbehind. this will only match the part you've requested.
(?<=.{2})(.*)$
You've updated your question and wrote that you use JavaScript. Lookbehind is not supported in JavaScript. However I will leave this answer for future search results.
If you want everything but the first two characters, you could try this (to capture up to the end of each line):
".{2}(.*)$"
You are after the first group (in parens). Or differently:
"(?:.{2})(.*)$"
The following will hold the matching string in the capturing group (define by the parenthesis) :
^.{2}(.+)
You should be able to use it with $1
or \1
depending on the language.
本文标签: javascriptRegular Expression to match everything but the first two charactersStack Overflow
版权声明:本文标题:javascript - Regular Expression to match everything but the first two characters - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741061833a2332810.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论