我想要一个正则表达式模式来查找字符串中的任何整数,但不是float(小数点为"."或",".所以对于字符串:
abc111.222dfg333hfg44.55
它应该只找到:
333
我创建了正则表达式模式:
(?<!\\d[\\.,]|\\d)\\d+(?![\\.,]\\d+|\\d)
Run Code Online (Sandbox Code Playgroud)
但在C++ STL正则表达式中使用时失败了.它抛出异常:
Unhandled exception at at 0x76AF4598 in xxxxxx.exe: Microsoft C++ exception: std::regex_error at memory location 0x00C1F218.
Run Code Online (Sandbox Code Playgroud)
但它在C#Regex类中运行良好
更新:
我的代码:
smatch intMatch;
regex e1("(?<!\\d[\\.,]|\\d)\\d+(?![\\.,]\\d+|\\d)");
string s("111.222dfg333hfg44.55");
regex_search ( s, intMatch, e1 );
Run Code Online (Sandbox Code Playgroud)
但它会引发异常:
regex e1("(?<!\\d[\\.,]|\\d)\\d+(?![\\.,]\\d+|\\d)");
Run Code Online (Sandbox Code Playgroud)
更新2:
两个答案都是正确的,但对于C++ STL正则表达式Toto一个更好.
编译以下代码时:
global main
extern printf, scanf
section .data
msg: db "Enter a number: ",10,0
format:db "%d",0
section .bss
number resb 4
section .text
main:
mov rdi, msg
mov al, 0
call printf
mov rsi, number
mov rdi, format
mov al, 0
call scanf
mov rdi,format
mov rsi,[number]
inc rsi
mov rax,0
call printf
ret
Run Code Online (Sandbox Code Playgroud)
使用:
nasm -f elf64 example.asm -o example.o
gcc -no-pie -m64 example.o -o example
Run Code Online (Sandbox Code Playgroud)
然后运行
./example
Run Code Online (Sandbox Code Playgroud)
它运行,打印:输入数字: 但随后崩溃并打印: 分段错误(核心已转储)
因此,printf可以正常工作,而scanf则不能。我对scanf有什么错呢?
为什么要低于线
<style type="text/css">
.on-the-fly-behavior {
background-image: url('particular_ad.png');
}
@media (max-width: 300px) {
.on-the-fly-behavior {
background-image: url('particular_ad_small.png');
}
}
</style>
Run Code Online (Sandbox Code Playgroud)
在浏览器中显示时,.cshtml文件中的“样式”标签中的抛出错误:
CS0103: The name 'media' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)