nsregularexpression

NSRegularExpression to extract text between two XML tags

江枫思渺然 提交于 2019-12-04 03:46:20
How to extract the value "6" between the "badgeCount" tags using NSRegularExpression. Following is the response from the server: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><badgeCount>6</badgeCount><rank>2</rank><screenName>myName</screenName> Following is the code I tried but not getting success. Actually it goes in else part and prints "Value of regex is nil": NSString *responseString = [[NSString alloc] initWithBytes:[responseDataForCrntUser bytes] length:responseDataForCrntUser.length encoding:NSUTF8StringEncoding]; NSError *error; NSRegularExpression *regex =

How can I use NSRegularExpression on Swift strings with variable-width Unicode characters?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 02:54:32
I'm having trouble getting NSRegularExpression to match patterns on strings with wider (?) Unicode characters in them. It looks like the problem is the range parameter -- Swift counts individual Unicode characters, while Objective-C treats strings as if they're made up of UTF-16 code units. Here is my test string and two regular expressions: let str = "dog🐶🐮cow" let dogRegex = NSRegularExpression(pattern: "d.g", options: nil, error: nil)! let cowRegex = NSRegularExpression(pattern: "c.w", options: nil, error: nil)! I can match the first regex with no problems: let dogMatch = dogRegex

Parsing HTML NSRegularExpression

天大地大妈咪最大 提交于 2019-12-04 02:33:17
问题 i'm trying to parse an HTML page using NSRegularExpressions.. The page is a repetition of this html code: <div class="fact" id="fact66">STRING THAT I WANT</div> <div class="vote"> <a href="index.php?p=detail_fact&fact=106">#106</a>     <span id="p106">246080 / 8.59 </span>     <span id="f106" class="vote2"> <a href="#" onclick="xajax_voter(106,3); return false;">(+++)</a> <a href="#" onclick="xajax_voter(106,2); return false;">(++)</a> <a href="#" onclick="xajax_voter(106,1); return false;">(

NSRegularExpression

我只是一个虾纸丫 提交于 2019-12-03 22:42:10
I have a string like: ?key=123%252Bf-34Fa&name=John ?name=Johon&key=123%252Bf-34Fa I want to get the value for the key ,I use this NSRegularExpression (?i)(?<=key=)[.?!&]+[?=&]?? What I think is that the pattern is like matching any character except "&".But the result is always NULL . the value of each key can have anything except "&". So How can I create the correct NSRegularExpression? thanks. You shouldn't use a regex for this, specially if you don't know how. Compare: NSString *string = @"?name=Johon&key=123%252Bf-34Fa"; // NSString *string = @"?key=123%252Bf-34Fa&name=John"; // one way

NSDate detection with NSDataDetector

北慕城南 提交于 2019-12-03 09:41:08
问题 I tried to get a NSDate from a NSString with UNKNOWN format, So I wrote a function like below -(void)dateFromString:(NSString*)string { NSError *error = NULL; NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:(NSTextCheckingTypes)NSTextCheckingTypeDate error:&error]; NSArray *matches = [detector matchesInString:string options:0 range:NSMakeRange(0, [string length])]; NSLocale* currentLoc = [NSLocale currentLocale]; for (NSTextCheckingResult *match in matches) { if ([match

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

孤人 提交于 2019-12-02 18:39:01
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 appear and show a list of hashtags, but what I can't figure out is how to do the following: Get the NSRange of the current word being typed, See if that range is formatted like a hashtag ( NSRegularExpression @"#\\w\\w*" ) (From here on out, I've got the code figured out to search for matching hashtags and show them in the UITableView) Can anyone

Regular Expression block negation

巧了我就是萌 提交于 2019-12-02 16:15:20
问题 I want to find out a string in which a particular tag does not occur, such as: <xyz>[\w]+<[^(unwanted)]></xyz> where unwanted will be interpreted as a , d , e , n , t and u . But what I want is a block string. How can I express it in regular expression? I have tried negative lookahead, which doesn't work: <xyz>.+(?!unwanted).+</xyz> 回答1: <xyz>(?:(?!unwanted).)+</xyz> Matches all chars in <xyz>...</xyz> , but only as long as the expression unwanted doesn't start at any of them. 来源: https:/

What are the correct regular expressions for syntax highlighting?

∥☆過路亽.° 提交于 2019-12-02 13:24:43
What are the correct regular expressions using NSRegularExpression for syntax highlighting? The following test must be passed: code // comment code /* comment */ code code "string" code code // comment code code /* comment comment */ code code "string code" string code "string\ string" code code // comment "comment" code /* comment "comment" */ code code "string /* string */ // string" code code // comment "string" code /* comment "comment" */ code code "string /* comment */ // comment" string code "string\ /* string */ // string" code code // comment // comment code /* comment /* comment */

Regular Expression block negation

◇◆丶佛笑我妖孽 提交于 2019-12-02 08:45:24
I want to find out a string in which a particular tag does not occur, such as: <xyz>[\w]+<[^(unwanted)]></xyz> where unwanted will be interpreted as a , d , e , n , t and u . But what I want is a block string. How can I express it in regular expression? I have tried negative lookahead, which doesn't work: <xyz>.+(?!unwanted).+</xyz> <xyz>(?:(?!unwanted).)+</xyz> Matches all chars in <xyz>...</xyz> , but only as long as the expression unwanted doesn't start at any of them. 来源: https://stackoverflow.com/questions/14819125/regular-expression-block-negation

How to catch special indicated **characters** in an NSString and bold what's in between?

断了今生、忘了曾经 提交于 2019-12-02 06:58:22
问题 I'm having trouble bolding any characters between an indicated pair of "**" characters. For example, in this NSString: "The Fox has ran **around** the corner." should read: "The fox has ran around the corner" here is my code : NSString *questionString = queryString; NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:questionString]; NSRange range = [questionString rangeOfString:@"\\*([^**]+)\\*" options:NSRegularExpressionSearch