Products
GG网络技术分享 2025-03-18 16:15 1
Firstly sorry for my bad English. I\'m newbie with regex. I\'m trying to make auto translation. For example I have a text like:
/begin CHARACTERISTICAccPed_trqEngLow_MAP
\"Kennfeld für AWD\"
MAP
0x801B425C
Map_Xs16Ys16Ws16
1500.000
Trq
-500.0000
1000.000
FORMAT \"%8.3\"
EXTENDED_LIMITS -3276.800 3276.700
/begin AXIS_DESCR
STD_AXIS
Epm_nEng
EngN
16
0.00
10000.00
FORMAT \"%8.2\"
EXTENDED_LIMITS -16384.00 16383.50
DEPOSIT ABSOLUTE
/end AXIS_DESCR
/begin AXIS_DESCR
STD_AXIS
AccPed_rAPP
Prc
8
0.00
100.0000
FORMAT \"%8.4\"
EXTENDED_LIMITS -400.0000 399.9878
DEPOSIT ABSOLUTE
/end AXIS_DESCR
/end CHARACTERISTIC
I need to select all strings in \"\"
like \"Kennfeld für AWD\"
, but do not select where starts with %
(\"%8.3\"
) Is it possible at least? Thanks in advance.. P.S string may contain quotation marks inside, like \"Hello \"world\" !\"
It is very difficult for me.
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议首先抱歉我的英语不好。 我是正则表达式的新手。 我正在尝试进行自动翻译。 例如,我有一个文本,如:</ p>
/ begin CHARACTERISTIC AccPed_trqEngLow_MAP
“KennfeldfürAWD”
MAP
0x801B425C
Map_Xs16Ys16Ws16
1500.000 \\ n Trq
-500.0000
1000.000
格式“%8.3”
EXTENDED_LIMITS -3276.800 3276.700
/ start AXIS_DESCR
STD_AXIS
Epm_nEng
EngN
16
0.00
10000.00
格式“%8.2”
EXTENDED_LIMITS -16384.00 16383.50
DEPOSIT ABSOLUTE
/ end AXIS_DESCR
/ begin AXIS_DESCR
STD_AXIS
AccPed_rAPP
Prc
8
0.00
100.0000
格式“%8.4”
EXTENDED_LIMITS -400.0000 399.9878
DEPOSIT ABSOLUTE
/ end AXIS_DESCR
/ end CHARACTERISTIC
</ code> </ pre> \\ n
我需要选择“”</ code>中的所有字符串,如“KennfeldfürAWD”</ code>,但不要选择以%</ code开头的地方 >(“%8.3”</ code>)至少可以吗? 提前谢谢.. P.S字符串里面可能包含引号,比如“Hello”world“!”</ code>对我来说很难。</ p>
</ div>
网友观点:
/\\\\\"([^%].*)\\\\\"/g
matches all strings in quotes that don\'t start with a % symbol.
In javascript (es6) it would be:
const example = `/begin CHARACTERISTIC
AccPed_trqEngLow_MAP
\\\"Kennfeld für AWD\\\"
MAP
0x801B425C
Map_Xs16Ys16Ws16
1500.000
Trq
-500.0000
1000.000
FORMAT \\\"%8.3\\\"
EXTENDED_LIMITS -3276.800 3276.700
/end CHARACTERISTIC
`
let re = /\\\\\"([^%].*)\\\\\"/g;
let results = example.match(re);
console.log(results)
How about?
<?php$string = \'
WHATVER \\\"Kennfeld für AWD\\\"
FORMAT \\\"%8.3\\\"
\\\"Hello \\\"World\\\" !\\\"
FOO
BAR
FORMAT \\\"%8.2\\\"
FORMAT \\\"%8.4\\\"
/end CHARACTERISTIC\';
preg_match_all(\'/\\\"((?!\\%).+)\\\"/\', $string, $matches, PREG_PATTERN_ORDER);
echo \\\"<pre>\\\";
print_r($matches);
echo \\\"</pre>\\\";
JS高级特性ES6-正则表达式
1.正则表达式作用
- 给定的字符串是否符合正则表达式的过滤逻辑(匹配)
- 可以通过正则表达式,从字符串中获取我们想要的特定部分(提取)
- 强大的字符串替换能力(替换)
- 创建正则的第一种方法,正则的字面量,推荐
Demand feedback