如何指定在C#正则表达式语句通配符(任意字符)?通配符、语句、字符、正则表达式

2023-09-06 06:02:09 作者:时光深存少年梦i

试图使用通配符在C#中抓住从网页源的信息,但我似乎无法找出作为通配符来使用的。没有我试过的作品!

Trying to use a wildcard in C# to grab information from a webpage source, but I cannot seem to figure out what to use as the wildcard character. Nothing I've tried works!

通配符只需要以允许数字,但作为页产生相同的每个的时间,我也不妨允许任何字符。

The wildcard only needs to allow for numbers, but as the page is generated the same every time, I may as well allow for any characters.

在使用正则表达式语句:

Regex statement in use:

Regex guestbookWidgetIDregex = new Regex("GuestbookWidget(' INSERT WILDCARD HERE ', '(.*?)', 500);", RegexOptions.IgnoreCase);

如果任何人都可以找出我做错了,那将是极大的AP preciated!

If anyone can figure out what I'm doing wrong, it would be greatly appreciated!

推荐答案

通配符是。 要匹配任意数量的任意字符,使用。* (即零个或多个)或者 + (这意味着一个或多个

The wildcard character is .. To match any number of arbitrary characters, use .* (which means zero or more .) or .+ (which means one or more .)

请注意,你需要逃避你的括号为 \\( \\)。 (或 \( \) @字符串)

Note that you need to escape your parentheses as \\( and \\). (or \( and \) in an @"" string)

 
精彩推荐
图片推荐