开发者

Regular Expression for number.(space), objective-c

I have an NSArray of lines (objective-c iphone), and I'm trying to find the line which starts with a number, followed by a dot and a space, but can have any number of spaces (including none) before it, and have any text following it eg:

    1. random text
           2. text random
3.

what regular expression would I use to get this? (I'm trying to learn it, and I needed the above expression anyway, so I thought I'd开发者_StackOverflow中文版 use it as an example)


With C#:

@"^ *[0-9]+\. "

It doesn't check for the presence of something after the ., so this is legal:

1.(space)

If you delete the @ and escape the \ it should work with other languages (it is pretty "down-to-earth" as RegExpes go)


I may suggest (Perl-compatible regexp):

^\s*\d+\.\s

At the beginning of a line:

  • Any number (0-n) of spaces
  • One or more digits
  • A dot
  • A space


Something like

^\s*\d+\.

But it depends on the language.


/^\s*[0-9]+\.\s+/

would be my guess providing you don't have any space before the number

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜