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

iOS email address validation

I've got a form and what I'm trying to do is validate email addresses before they're inserted into my database. I've read multiple posts on this already and none of them have solved my problem. This is the code that I have so far. -(BOOL)…
mhorgan
  • 886
  • 2
  • 11
  • 32
4
votes
4 answers

NSRegularExpression with arithmetic

I would like to change the font-size in an HTML string that I have to be half of its size. E.g.
Will be
and
Dejell
  • 13,947
  • 40
  • 146
  • 229
4
votes
1 answer

Regex in Objective-c not working as intended

I use Regex for checking a password. But it is not working as intended. I use some Unit-tests to check the regex. @implementation NSString (regexMatch) - (BOOL)matchesRegex:(NSString *)regexPattern { NSError *error = nil; …
Justin
  • 2,960
  • 2
  • 34
  • 48
3
votes
2 answers

Why does NSRegularExpression not honor capture groups in all cases?

Main problem: ObjC can tell me there were six matches when my pattern is, @"\\b(\\S+)\\b", but when my pattern is @"A b (c) or (d)", it only reports one match, "c". Solution Here's a function which returns the capture groups as an NSArray. I'm an…
JD.
  • 3,005
  • 2
  • 26
  • 37
3
votes
1 answer

Replace same character on one line multiple times Notepad++

I have a many files and in each file there is a line with the following (amongst other things). This line is not always in the same place, however, it starts from the beginning of the line. This line is also always different. slug:…
Kenneth Browning
  • 1,360
  • 1
  • 13
  • 22
3
votes
1 answer

String extension for matching regular expression

I have 2 functions written in Swift 2, but Apple forced me to migrate to Swift 4 and I can't fix the functions. extension String { func stringsMatchingRegularExpression(expression: String) -> [String] { if let range =…
Bogdan Bogdanov
  • 882
  • 11
  • 36
  • 79
3
votes
1 answer

Regex for currency - Exclude commas from the count limit

I am using the following regex in my app: ^(([0-9|(\\,)]{0,10})?)?(\\.[0-9]{0,2})?$ So it allows 10 characters before the decimal and 2 character after it. But I am inserting one additional functionality of formatting textfield as currency while…
Mamta
  • 921
  • 1
  • 10
  • 28
3
votes
3 answers

Regular expression for optional character in between the numerals

I need to validate a string that contains underscore(_) in between the numbers. Underscore character is an optional. Only condition is, it should be between the numbers. Valid => 123 Valid => 1_23 Valid => 123_4567_89_312_575 Not valid…
Pradeep Rajkumar
  • 919
  • 2
  • 12
  • 27
3
votes
1 answer

NSRegularExpression.replacementString doesn't track changes in string length

I'm trying to write some code where I iterate over regex matches in a string and run an operation on the match, replacing it with the result of the operation. I'm running into problems though, where inside my replacementString() override the…
mpounsett
  • 1,174
  • 1
  • 10
  • 30
3
votes
1 answer

Is there a function to escape all regex-relevant characters?

The regex I'm using in my application is a combination of user-input and code. Because I don't want to restrict the user I would like to escape all regex-relevant characters like "+", brackets , slashes etc. from the entry. Is there a function for…
LarsGvB
  • 267
  • 3
  • 11
3
votes
1 answer

A protein-coded gene Regular Expression

I am trying to write a regex that can match the following instructions A sequence of character with the “AT” prefix, followed by “nG” where n is a digit from 1 through 5 and then "G" and lastly followed by a suffix of 5 numeric digits. Note: just…
tony pro
  • 405
  • 3
  • 12
3
votes
2 answers

Swift: Finding an Object Property via regex

Target: The following function shall iterate over an array of objects and check a specific property of all objects. This property is a string and shall be matched with a user input via regex. If there's a match the object shall be added to an array…
procra
  • 535
  • 4
  • 29
3
votes
1 answer

swift - how can I remove blank(empty) line in NSAttributedString?

I'm making a Note-Taking-App. I save Attributed text On DetailVC and I show the preview in the UITableViewCell label. In the label I have a text like this The Bold Title my Text and I want to change this like The Bold Title my Text I found the…
Daniel
  • 521
  • 1
  • 7
  • 16
3
votes
1 answer

How do I find words written in Thai with NSRegularExpression

I have a word written in the thai language--> ความรัก How do I use NSRegularExpression to match this word? I tried using the exact word but it is not working. It is not even working on sites like regex101.com Here is my code (swift version. But…
swift nub
  • 2,747
  • 3
  • 17
  • 39
3
votes
1 answer

iOS Split NSString with Regular Expression

I am using this code to parse NSString: NSString *string = @"{{nat fs g player|no=1|pos=GK|name=[[Hugo Lloris]]|age={{Birth date and age|1986|12|26|df=y}}|caps=73|goals=0|club=[[Tottenham Hotspur F.C.|Tottenham Hotspur]]|clubnat=ENG}}"; NSError…
YosiFZ
  • 7,792
  • 21
  • 114
  • 221