简体   繁体   English

正则表达式不捕获第一个字符

[英]regex don't capture 1st character

I want to capture every letter except the first letter in the string. 我想捕获字符串中除第一个字母以外的所有字母。
Example string: The cat in the hat. 示例字符串: The cat in the hat.

I know to capture the first letter is /[^]/ so I would want something like /not [^]/ 我知道要捕获的第一个字母是/[^]/所以我想要类似/not [^]/

Use a zero width positive lookbehind: 在后面使用零宽度正向查找:

(?<=^.).*

Demo 演示版

You can utilize a capture group with a basic regular expression. 您可以使用具有基本正则表达式的捕获组。

^.(.*)

The capture group stores the match result ignoring the first character in the string. 捕获组将忽略字符串中的第一个字符而存储匹配结果。

Demo 演示版

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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