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
6
votes
2 answers

Suggest # tags while typing (like Twitter) for iPhone UITextView

I'd building an app that uses hashtags, like Twitter or Tweetbot. When you're typing a message, if you type the hashtag symbol, I'd like to suggest tags that match the current one you're typing. I've already figured out how to get the UITableView to…
bryanjclark
  • 6,247
  • 2
  • 35
  • 68
6
votes
4 answers

URL Validation (Objective-C)

I am trying to validate a URL with this method: Code: - (BOOL) validateUrl: (NSString *) candidate { NSString *urlRegEx= @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"; NSPredicate…
saleh Hosseinkahni
  • 497
  • 2
  • 6
  • 17
6
votes
1 answer

'self' used inside 'catch' block reachable from super.init call

This code is not compiling on Swift 3.3. It's showing the message: 'self' used inside 'catch' block reachable from super.init call public class MyRegex : NSRegularExpression { public init(pattern: String) { do { try…
cristianomad
  • 303
  • 2
  • 9
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
  • 12,319
  • 23
  • 93
  • 186
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
  • 173
  • 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,584
  • 1
  • 37
  • 53
5
votes
1 answer

How to use a named capture group in VS code Find/Replace?

In the vs code find/replace editor widget, I'm using a named capture group (?.*\s*). I'm then using ${end}in the replace but its just putting the literal text there instead of the captured contents. The unnamed capture groups are working as…
default
  • 2,637
  • 21
  • 44
5
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
  • 707
  • 2
  • 10
  • 23
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,217
  • 4
  • 43
  • 79
5
votes
6 answers

Strip leading, trailing and more than 1 space from String

I have string: Simple text with spaces I need regular expression which select: leading trailing more than 1 space Example: _ - space _Simple text __with ___spaces_
Artem Krachulov
  • 557
  • 6
  • 23
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,906
  • 2
  • 21
  • 47
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,455
  • 4
  • 28
  • 38
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
  • 26,573
  • 48
  • 165
  • 294
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
  • 350
  • 2
  • 4
  • 12
1 2
3
48 49