Questions tagged [nsregularexpression]

The NSRegularExpression class is used to represent and apply regular expressions to Unicode strings. An instance of this class is an immutable representation of a compiled regular expression pattern and various option flags. The pattern syntax currently supported is that specified by ICU. iOS 4.0+ macOS 10.7+

This class in the Apple developer library (Mac OS X, iOS) is used to represent and apply regular expressions to Unicode strings.

NOTE: This tag should be used only for questions specific to the NSRegularExpression class. Questions about regular expressions in general should be tagged .

643 questions
6
votes
2 answers

How to use regular expressions in Swift 3?

I wanted to follow this tutorial to learn about NSRegularExpression in Swift, but it has not been updated to Swift 3. When I open the playground with the examples they provide, I get several errors being one of them the call: let regex =…
AppsDev
  • 11,441
  • 20
  • 81
  • 163
6
votes
3 answers

How to use regular expressions to find words that begin with a three character prefix

My goal is to count the number of words (in a string) that begin with a specified prefix of more than one letter. A case is words that begin with "non". So in this example... NSString * theFullTestString = @"nonsense non-issue anonymous…
Han
  • 153
  • 1
  • 9
6
votes
4 answers

Regex pattern and/or NSRegularExpression a bit too slow searching over very large file, can it be optimized?

In an iOS framework, I am searching through this 3.2 MB file for pronunciations: https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/pocketsphinx/model/lm/en_US/cmu07a.dic I am using NSRegularExpression to search for an arbitrary set of…
Halle
  • 3,557
  • 1
  • 33
  • 53
5
votes
1 answer

NSRegularExpression cannot find capturing group matches

I'm trying to parse a string using one regular expression pattern. Here is the pattern: (\")(.+)(\")\s*(\{) Here is the text to be parsed: "base" { I want to find these 4 capturing groups: 1. " 2. base 3. " 4. { I am using the following code…
Tomasz Szulc
  • 4,081
  • 3
  • 38
  • 78
5
votes
1 answer

Swift Regex matching fails when source contains unicode characters

I'm trying to do a simple regex match using NSRegularExpression, but I'm having some problems matching the string when the source contains multibyte characters: let string = "D 9" // The following matches (any characters)(SPACE)(numbers)(any…
5
votes
3 answers

Regular expression in ios to extract href url and discard rest of anchor tag?

I want to write a url extracting function in objective C. The input text can be anything and may or may not contain html anchor tags. Consider this: NSString* input1 = @"This is cool site Have fun exploring…
5
votes
2 answers

Objective-C NSRegularExpressions, finding first occurrence of numbers in a string

I'm pretty green at regex with Objective-C. I'm having some difficulty with it. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\b([1-9]+)\\b" options:NSRegularExpressionCaseInsensitive error:®Error]; if…
rnystrom
  • 1,866
  • 2
  • 20
  • 45
5
votes
1 answer

NSRegularExpression enumerateMatchesInString:options:range:usingBlock: giving a null result?

I'm using a regular expression in a parser, however, it seems to give one result to much, this is my code: Regex: self.seatSelectRegex = [NSRegularExpression regularExpressionWithPattern:@"Seat ([0-9]{1,2}): (.*) \\([$£€]?([0-9.]+) in chips\\).*$"…
Sander Declerck
  • 2,117
  • 4
  • 25
  • 36
4
votes
1 answer

NSRegularExpression, specify case-sensitive match?

Is there a way using NSRegularExpression to specify that you want to do a case-sensitive search? I am trying to match the upper-case TAG "ACL" in the text below. The pattern I am using is simply: // Pattern [A-Z]+ // SearchText
fuzzygoat
  • 25,797
  • 45
  • 159
  • 288
4
votes
7 answers

Email Validation in iOS

Email validation checking in iPhone programming can be done using RegexKitLite library (iOS2.0), NSPredicate (iOS 3.0 onwards) and NSRegularExpression (iOS 4.0). But can anybody state what is the advantage of one over the other and which is the best…
user574089
  • 354
  • 2
  • 4
  • 12
4
votes
5 answers

Regular expressions in swift

I'm bit confused by NSRegularExpression in swift, can any one help me? task:1 given ("name","john","name of john") then I should get ["name","john","name of john"]. Here I should avoid the brackets. task:2 given ("name"," john","name of…
Damodar
  • 527
  • 8
  • 23
4
votes
2 answers

Swift - Splitting strings with regex - ignoring search string

There is a clever 1st answer given here for splitting swift string with a regex expression split string answer However it keeps the searched text within the array of answers. I'm trying to do a similar thing, but ignoring the characters acting as…
domc
  • 147
  • 12
4
votes
1 answer

Regular Expression to Match Non-Whitespace Characters

I need to make a regular expression that matches something like: JG2144-141/hello or ! but not: laptop bag or a string consisting of whitespace chars only (' '). Right now I have [A-Za-z0-9-!/\S], but it isn't working because it still matches…
Jennifer Hall
  • 41
  • 1
  • 4
4
votes
2 answers

trying to parse a Localizable.string file for a small project in swift on MacOS

I'm trying to parse a Localizable.string file for a small project in swift on MacOS. I just want to retrieve all the keys and values inside a file to sort them into a dictionary. To do so I used regex with the NSRegularExpression cocoa class. Here…
Edgar
  • 193
  • 9
4
votes
1 answer

How to remove text within parentheses using NSRegularExpression?

I try to remove part of the string which is inside parentheses. As an example, for the string "(This should be removed) and only this part should remain", after using NSRegularExpression it should become "and only this part should remain". I have…
Bastek
  • 869
  • 12
  • 26
1 2
3
42 43