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

RegEx works online in RegexR but fails to initialise on iOS in NSRegularExpression

I have a regex designed to extract the git URL from a CocoaPods definition. The input text is as follows: pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev' The regex is as follows: (?<=('Alamofire'.*:git =>…
Jacob King
  • 6,025
  • 4
  • 27
  • 45
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
  • 1
  • 12
4
votes
3 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
  • 203
  • 2
  • 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
  • 899
  • 1
  • 12
  • 27
4
votes
1 answer

How to see if a specific string matches a regex pattern?

I am trying to see if a specific string matches a regex pattern in swift. The code I have so far seems to check if any substring within the given string matches the regex. let string = " (5" let pattern = "[0-9]" if string.rangeOfString(pattern,…
Evan Cathcart
  • 635
  • 2
  • 10
  • 13
4
votes
2 answers

Swift - Regular Expression to match parentheses

I am trying to use regex to search through a string: "K1B92 (D) [56.094]" and I want to grab the "(D)" including the parentheses surrounding the "D". I am having trouble finding the correct expression to match the actual parentheses as simply…
joanna cheung
  • 161
  • 3
  • 9
4
votes
1 answer

Find all HTML sibling element in iOS

I have a huge HTML, but at a certain level there are 10 piece of article element. I need theme.
4
votes
3 answers

How to remove 100s of warnings "implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int'" I got after updating to arm64?

Problem: Yesterday I converted a large project of mine to support arm64 and after that I got 500+ warnings at once. About 70% of them are where NSInteger is being assigned to int or vice versa, and remaining are where NSUInteger is formatted in…
4
votes
3 answers

How do I repeat a capturing group?

I have an input string that looks something like this: HLI6Ch60000Ch500C0Ch46400Ch30000Ch21888Ch10E79CS07LCU3Ch37880Ch27800Ch16480CS8CA00000000000000000000 Now I don't care about the part that follows the last letter A, it'll always be A and…
Cellane
  • 511
  • 1
  • 6
  • 16
4
votes
1 answer

Does NSRegularExpression support partial case insensitive?

As the title states, I wonder if NSRegularExpression in both Objective-c or Swift, support partial case insensitive search? Namely, will the pattern recognize (?ismx)? If not, is there a brief reason for this inability? I truly appreciate your…
donkey
  • 4,285
  • 7
  • 42
  • 68
4
votes
1 answer

Cocoa error 2048 when using NSRegularExpression in Cocoa

I'm building a regular expression for use in a parser in an iOS app. Here's my code: NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=#EXT[^\r\n]*[\r\n]+)[^#][^\r\n]+" …
Eric
  • 16,003
  • 15
  • 87
  • 139
4
votes
4 answers

How do I check for this odd space character - " " in Objective-C?

I wrote some RegEx to play with spaces in strings, and it works beautifully, except for when I come across this character: " " instead of " ". You probably think I'm crazy, but apparently they're different. Check out this RegEx app (oddly enough, it…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
4
votes
1 answer

objective c - help creating regular expression for format (#,#)

A user enters his/her number of credit hours per course in my UITextField in this format.... 4,3,4,3,3 (4 credit hours for 1st course, 3 credit hours for 2nd course, so on) Conditions: The user can only enter in MIN of 1 course and MAX 5 courses,…
bean22
  • 41
  • 1
4
votes
2 answers

Searching for the words with brackets placed around them in iOS

I am trying to search for all words with brackets around them in a group of text and change it to italic in iOS. I am using this code to search for brackets in the text: static inline NSRegularExpression * ParenthesisRegularExpression() { static…
lakshmen
  • 28,346
  • 66
  • 178
  • 276
4
votes
2 answers

NSRegularExpression acts weird (and the regex is correct)

I've got this regex ([0-9]+)\(([0-9]+),([0-9]+)\) that I'm using to construct a NSRegularExpression with no options (0). That expression should match strings like 1(135,252) and yield three matches: 1, 135, 252. Now, I've confirmed with…
Morpheu5
  • 2,610
  • 6
  • 39
  • 72