简体   繁体   中英

How to match all characters after nth character with regex in JavaScript?

I want to match all characters after 8th character. And not include first 8!

I need exactly a regular expression cause a framework (Ace.js) requires a regexp, not a string. So, this is not an option:

var substring = "123456789".substr(5);

Can I match everything after nth character using regex in JavaScript?

Updates: I can't call replace() , substring() etc because I don't have a string. The string is known at run time and I don't have access to it. As I already said above the framework (Ace.js) asks me for a regex.

(?<=^.{8}).* 

will match everything after the 7th position. Matches 89 in 0123456789

or IJKLM in ABCDEFGHIJKLM

etc

console.log("123456789".match(/^.{8}(.*)/)[1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM