nsregularexpression

Does NSRegularExpression support partial case insensitive?

孤街醉人 提交于 2019-12-10 09:36:06
问题 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 explanation. 回答1: From the NSRegularExpression Class Reference: Table 2 Regular Expression Operators ... (?ismwx-ismwx:...) Flag settings. Evaluate the parenthesized expression with the specified flags enabled or -disabled. ... (?ismwx-ismwx) Flag

How do I repeat a capturing group?

允我心安 提交于 2019-12-09 22:06:23
问题 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 exactly 20 numbers that are of no use to me. I do, however, need the part before the last letter A , and ideally, I'd need it to be separated into two different captures, just like this: 1: HLI6Ch60000Ch500C0Ch46400Ch30000Ch21888Ch10E79CS07 2:

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

自闭症网瘾萝莉.ら 提交于 2019-12-08 18:35:19
问题 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 I used componentSeparatedByString:@"," method! It is successfully returning me the array with three components: Christopher Bass Cry the Beloved Country Final Essay cbass@cgs.k12.va.us but when there is already a comma in the column value, like

Example of using NSRegularExpression to detect if string contains Cyrillic

风流意气都作罢 提交于 2019-12-08 09:17:53
问题 I looked into the Apple reference on NSRegularExpression , and understand that in order see if the string is Cyrillic I should use \p{script=cyrillic} . However, I have not been able to find an actual example of how this is done in the reference guide or in an answer located in SO. What I would ideally like to achieve is: if (string contains \p{script=cyrillic}){ return YES; } else { return NO; } 回答1: Maybe (I am an iOS programming newbie): - (BOOL)containsCyrillic:(NSString*)str { NSString*

Regex stringByReplacingMatchesInString

别来无恙 提交于 2019-12-08 08:49:08
问题 I'm trying to remove any non-alphanumeric character within a string. I tried the following code snippet, but it is not replacing the appropriate character. NSString *theString = @"\"day's\""; NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^\\B\\W^\\B" options:NSRegularExpressionCaseInsensitive error:&error]; NSString *newString = [regex stringByReplacingMatchesInString:theString options:0 range:NSMakeRange(0, [theString length])

how to exclude some url from a regex match

那年仲夏 提交于 2019-12-08 07:54:33
问题 I have 3 type payment ( online, offline, by balance) every payment type have different url so I'm using regex for match all this url : 1- order/checkout/unpaid/done 2- order/checkout/paid/done?Authority=000000000000000000000000000039067905&Status=OK 3- order/checkout/paid/done?Status=OK regex : (.*?)done this regex match all of urls but the problem is it match some page too ! kile this product page : /tork- done r-motahari-tehran What is the solution ? 回答1: You may use (.*)done($|[?]) The

Regex Expression For a String

你说的曾经没有我的故事 提交于 2019-12-08 02:45:55
问题 I want to split the string in python. Sample string: Hi this is ACT I. SCENE 1 and SCENE 2 and this is ACT II. SCENE 1 and SCENE 2 and more into the following list: ['Hi this is', 'ACT I. SCENE 1', 'and', 'SCENE2', 'and this is', 'ACT II. SCENE 1', 'and' , 'SCENE 2', 'and more'] Can someone help me build the regex? The one that I have built is: (ACT [A-Z]+.\sSCENE\s[0-9]+)]?(.*)(SCENE [0-9]+) But this is not working properly. 回答1: If I understand your requirements correctly, you may use the

Swift Regex matching fails when source contains unicode characters

孤者浪人 提交于 2019-12-07 08:39:08
问题 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 characters) let pattern = "([\\s\\S]*) ([0-9]*)(.*)" let slen : Int = string.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) var error: NSError? = nil var regex = NSRegularExpression(pattern: pattern, options: NSRegularExpressionOptions

Replace regex matches in attributed string with image in Objective-C

旧巷老猫 提交于 2019-12-06 11:54:38
问题 My goal is to store the information for an attributed string in Parse.com. I decided to come up with an encoding for attributed text for my images that works by replacing any string {X} in braces with the corresponding image. For example: Picture of 2 colorless mana: {X} Should produce an attributed string where {X} is replaced by an image. This is what I've tried: NSString *formattedText = @"This will cost {2}{PW}{PW} to cast."; NSRegularExpression *regex = [NSRegularExpression

Regex Expression For a String

点点圈 提交于 2019-12-06 07:13:34
I want to split the string in python. Sample string: Hi this is ACT I. SCENE 1 and SCENE 2 and this is ACT II. SCENE 1 and SCENE 2 and more into the following list: ['Hi this is', 'ACT I. SCENE 1', 'and', 'SCENE2', 'and this is', 'ACT II. SCENE 1', 'and' , 'SCENE 2', 'and more'] Can someone help me build the regex? The one that I have built is: (ACT [A-Z]+.\sSCENE\s[0-9]+)]?(.*)(SCENE [0-9]+) But this is not working properly. If I understand your requirements correctly, you may use the following pattern: (?:ACT|SCENE).+?\d+|\S.*?(?=\s?(?:ACT|SCENE|$)) Demo . Breakdown: (?: # Start of a non