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
3
votes
3 answers

Can't do regex matching

Hi I need phone number validation for France. Valid format : +262######### Validation done in textDidChang: so every I need to check every number belong to above number. My Regex below [[NSPredicate predicateWithFormat:@"SELF MATCHES %@",…
TamilKing
  • 1,643
  • 1
  • 12
  • 23
3
votes
1 answer

Extract word or character after matched string excluding whiteSpace and matched string using regex

"1 cup of Greek or natural yoghurt." I want cup to be filtered out. "1gm of salt." Here i want gm to be extracted. I want a regex expression which is the combination of both. Any help would be appriciated.
user1068810
  • 387
  • 2
  • 6
  • 14
3
votes
1 answer

Captured group regex NSRegularExpression iOS

I am trying to execute the following regex: ^(\$.)([\d]{1,10})? The result for the $C14325 string at https://regex101.com is [0-2]:"$C" and [2-7]:"14325". But, when I the following code is executed using NSRegularExpression, then it returns as…
NNikN
  • 3,720
  • 6
  • 44
  • 86
3
votes
2 answers

REGEX to get Next Previous word

I want next and previous word of which I searched with REGEX that I can get with pattern as below. In this case I have searched word "the", So I can get next and previous word of "the". That I can get successfully with following…
Niks
  • 647
  • 5
  • 16
3
votes
1 answer

Regex in Swift not working when escaping backslashes

I have a regex that I'm trying to use in Swift to parse out the color values of a string in the form of "rgba(255, 255, 255, 1)" My regex string is…
erickreutz
  • 2,779
  • 3
  • 21
  • 18
3
votes
1 answer

Why regex doesn't work? Swift

I have this regex expression that works on http://www.regexr.com but not in iOS. Anyone know what's wrong? let regex = NSRegularExpression(pattern: "v=(.+?)(?=\\s|&)", options: NSRegularExpressionOptions.CaseInsensitive, error: &error) Original…
mhergon
  • 1,688
  • 1
  • 18
  • 39
3
votes
3 answers

Regular expression to check for integer or decimal number in iOS

I need to check whether the text is an integer or a decimal number. I tried using the following: NSString *expression = @"\\d*"; NSError *error ; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:expression…
skyler
  • 742
  • 1
  • 10
  • 24
3
votes
2 answers

RegEx .+ does not include space and new line characters

My RegEx \\s*[+-].+\\s*\\n*\\s*[{] is not able to find below method of UITableView, but it reads all other methods written in a single line. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle…
Zeeshan
  • 586
  • 7
  • 15
3
votes
2 answers

Non-greedy regex match when searching from end

I read that you should use ? to match text non-greedily, so the regex http://.*?\.png ...used on http://example.png.png ...would return http://example.png. But the non-greediness only seems to work from left to right. That is, if I matched it…
Jessica
  • 2,335
  • 2
  • 23
  • 36
3
votes
0 answers

What's wrong with my NSRegularExpression?

NSString *body = @"..."; // Remove all HTML and formatting from body NSError *error = nil; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(<.*?>|\\n|\\t|&.*?;)"…
user212541
  • 1,878
  • 1
  • 21
  • 30
3
votes
3 answers

How can I parse a string to extract numbers with a regular expression using NSRegularExpression?

I am new to regular expressions and have no clue how to work with them. I wanted to create a regex for the below piece of text to fetch the min, avg & max time. I would be using them with NSRegularExpression to fetch the range & then the string.…
Abhinav
  • 37,684
  • 43
  • 191
  • 309
3
votes
1 answer

NSRegularExpression memory hog

I have been trying to bring down the memory usage of my app, and after profiling it turns out that NSRegularExpression is quite a memory hog. One of my fistMatchInString calls (the first one?) allocates 1 MB of memory which is never released. And…
fishinear
  • 6,101
  • 3
  • 36
  • 84
2
votes
2 answers

Extract parts from regular expression with NSRegularExpression

I want extract parts of a string with NSRegularExpression. For example, I have this string: @"1 UIKit 0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163"; And I want extract…
intropedro
  • 2,804
  • 1
  • 24
  • 25
2
votes
1 answer

NSRegularExpression escaping parentheses

I'm using regular expressions to find some values in a string, however, what I'm trying to find looks something like this: Dealt to SanderDecler [2s 5d] But I can't seem to find a way to escape these square brackets, I've had the same problem with…
Sander Declerck
  • 2,455
  • 4
  • 28
  • 38
2
votes
2 answers

capturing a string before and after some data using regular expressions in ObjectiveC

I am relatively new to regex expressions and needed some advice. The goal is to the get data in the following format into an array: value=777 value=888 From this data: "value=!@#777!@#value=@#$888*" Here is my code (Objective C): NSString…
Just a coder
  • 15,480
  • 16
  • 85
  • 138