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 .

722 questions
8
votes
2 answers

NSRegularExpression to extract text between two XML tags

How to extract the value "6" between the "badgeCount" tags using NSRegularExpression. Following is the response from the server:
Prazi
  • 335
  • 1
  • 5
  • 18
8
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
  • 81
  • 1
  • 1
  • 4
8
votes
2 answers

Is there an Objective-c regex replace with callback/C# MatchEvaluator equivalent?

I have a C# project I'm intending to port to Objective-C. From what I understand about Obj-C, it looks like there's a confusing variety of Regex options but I can't see anything about a way of doing a replace with callback. I'm looking for…
Michael Low
  • 24,276
  • 16
  • 82
  • 119
8
votes
2 answers

Case and diacritic insensitive matching of regex with metacharacter in Swift

I am trying to match rude words in user inputs, for example "I Hate You!" or "i.håté.Yoù" will match with "hate you" in an array of words parsed from JSON. So I need it to be case and diacritic insensitive and to treat whitespaces in the rude words…
CyrilFind
  • 634
  • 1
  • 7
  • 16
8
votes
1 answer

Ignore escaped double quote characters swift

I am trying to validate a phone number using NSPredicate and regex. The only problem is when setting the regex Swift thinks that I am trying to escape part of it due to the backslashes. How can I get around this? My code is as follows: let…
Jacob King
  • 6,025
  • 4
  • 27
  • 45
8
votes
2 answers

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…
NEIL STRONG
  • 113
  • 7
8
votes
4 answers

Named capture groups with NSRegularExpression

Does NSRegularExpression support named capture groups? It doesn't look like it from the documentation, but I wanted to check before I explore alternative solutions.
Dov
  • 15,530
  • 13
  • 76
  • 177
7
votes
5 answers

How to use regular expression in iPhone app to separate string by , (comma)

I have to read .csv file which has three columns. While parsing the .csv file, I get the string in this format Christopher Bass,\"Cry the Beloved Country Final Essay\",cbass@cgs.k12.va.us. I want to store the values of three columns in an Array, so…
Developer
  • 6,375
  • 12
  • 58
  • 92
7
votes
1 answer

Do any of the flavors of regex in Regex Buddy coincide with NSRegularExpression (ICU) regex?

NSRegularExpression says its flavor of regex is "ICU." I have RegexBuddy, which supports a bunch of different flavors, but none of them calls itself "ICU." But is one of them ICU under another name?
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
7
votes
2 answers

iOS regular expression arabic

I come from this posts Regular Expression Arabic characters and numbers only How to match arabic words with reg exp? (didn't answer my question) I've tried ^[\p{Arabic} ]+$ and received 'Parse error', reason: 'Invalid escape sequence @ pos 3: ^[\ …
Ted
  • 22,696
  • 11
  • 95
  • 109
7
votes
4 answers

How to check the validity of a GUID (or UUID) using NSRegularExpression or any other effective way in Objective-C

The method should return TRUE if the NSString is something like @"{A5B8A206-E14D-429B-BEB0-2DD0575F3BC0}" and FALSE for a NSString like @"bla bla bla" I am using something like: - (BOOL)isValidGUID { NSError *error; NSRange range =…
Goppinath
  • 10,569
  • 4
  • 22
  • 45
7
votes
2 answers

Extracting single values from a parsed NSString in objective-c

These are my sample NSStrings (parsed into an array), simplified. The single string object is parsed like "STRING1, STRING2 then DATE TIME then - A:VALUE", ex: The name of first value, first 17/04/2013 11:30:00 - A:30.0 // sometimes there is a comma…
SILminore
  • 509
  • 3
  • 10
  • 28
7
votes
2 answers

regular expression in ios to remove href links

i need some help in building a regular expression to remove href links with search terms from a long string that i then parse into a web view an example of the href string : Huntington i would like to remove…
7
votes
5 answers

regular expressions replace in iOS

I am going to need to replace a dirty string for a clean string: -(void)setTheFilter:(NSString*)filter { [filter retain]; [_theFilter release]; tmp = preg_replace(@"/[0-9]/",@"",filter); <~PSEUDO CODE> …
Ted
  • 3,805
  • 14
  • 56
  • 98
6
votes
1 answer

NSCheckingResult Range Property not set to {NSNotfound,0}?

From looking at the docs for NSTextCheckingResult I was under the impression that if no match in a NSRegularExpression search was found the range property for NSCheckingResult would be set to {NSNotFound,0} From my test below I am finding that if no…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
1
2
3
48 49