求助:使用正则表达式提取字符串参数及目标内容977-1071
977-1071 from Your Text with Regex Hey there! Let's sort out this regex problem and get you the exact string you need.
First, let's break down why your original regex /(Adm6000)([^\7]+)/ isn't working:
- The
[^\7]part is matching any character except the ASCII BEL control character (code 7)—not the number "7" in your text. That's a common mix-up with how regex character sets handle escape sequences. - Even if that part worked, your regex would capture everything after
Adm6000up to the first BEL character, which isn't what you're targeting.
The Correct Regex
Looking at your text structure: Adm6000/977-1071/047421CA414149E5CEC5—your target 977-1071 sits right between Adm6000/ and the next /.
Here are two reliable ways to capture it:
Using a Capture Group (perfect if you need to extract just this specific part):
/Adm6000\/([^\/]+)/Adm6000\/: Matches the literal stringAdm6000/(we escape the/with\because it acts as a regex delimiter).([^\/]+): Captures one or more characters that are not a/—this will exactly grab977-1071.
Using Positive Lookbehind (if you want to match the target directly without extra groups):
/(?<=Adm6000\/)[^\/]+/(?<=Adm6000\/): Checks thatAdm6000/comes right before the target (but doesn't include it in the final match).[^\/]+: Again, matches all characters until the next/.
Testing It
If you run either regex against your text:
BAYARPLN ke 116160029354, SUKSES. Hrg: 84.822. SN: TGK IMUM M SAMIN/R1/450/MAR,APR/Rp.89222/Adm6000/977-1071/047421CA414149E5CEC5. Saldo: 7
Both will correctly pick out 977-1071.
内容的提问来源于stack exchange,提问作者yagami cell

