nsregularexpression

Regular Expression to Match Non-Whitespace Characters

夙愿已清 提交于 2019-12-02 06:20:51
问题 I need to make a regular expression that matches something like: JG2144-141/hello or ! but not: laptop bag or a string consisting of whitespace chars only ( ' ' ). Right now I have [A-Za-z0-9-!/\S] , but it isn't working because it still matches with laptop and bag individually. It shouldn't match laptop bag and the empty string at all. 回答1: The \S in [A-Za-z0-9-!/\S] makes this character class equal to \S , but you want to make sure all chars in the string are non-whitespace chars. That is

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

こ雲淡風輕ζ 提交于 2019-12-02 05:47:16
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|NSCaseInsensitiveSearch]; if (range.location != NSNotFound) { [mutableAttributedString setAttributes:@

Parsing HTML NSRegularExpression

佐手、 提交于 2019-12-01 14:29:08
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;">(+)</a> <a href="#" onclick="xajax_berk(106); return false;">(-)</a></span> <span id="ve106"></span> <

iOS regular expression arabic

隐身守侯 提交于 2019-12-01 04:57:42
I come from this posts Regular Expression Arabic characters and numbers only How to match arabic words with reg exp? (didn't answer my question) I've tried ^[\p{Arabic} ]+$ and received 'Parse error', reason: 'Invalid escape sequence @ pos 3: ^[\ ▶p{Arabic} ]+$' I've also tried ^[\u0621-\u064A\s]+$ 'Parse error', reason: 'Invalid character range @ pos 7: ^[\u062 ▶1-\u064A\s]+$' I've also tried ^[\u0621-\u064A]+$ 'Parse error', reason: 'Invalid character range @ pos 7: ^[\u062 ▶1-\u064A]+$' I need ^[A-Za-z ]+$ that accepts arabic characters. Thanks in advance! This solved my issue Arabic text

NSRegularExpression enumerateMatchesInString:options:range:usingBlock: giving a null result?

无人久伴 提交于 2019-12-01 04:03:50
问题 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\\).*$" options:NSRegularExpressionAnchorsMatchLines error:&error]; Code: NSMutableDictionary *players = [[NSMutableDictionary alloc] init]; [self.seatSelectRegex enumerateMatchesInString:input options:NSMatchingCompleted range:NSMakeRange(0, input.length)

How to use regular expressions to find words that begin with a three character prefix

≯℡__Kan透↙ 提交于 2019-12-01 02:58:34
问题 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 controlWord"; ...I want to get hits on "nonsense" and "non-issue", but not on "anonymous" or "controlWord". The total count of my hits should be 2. So here's my test code which seems close, but none of the regular expression forms I've tried works correctly.

iOS regular expression arabic

こ雲淡風輕ζ 提交于 2019-12-01 02:15:28
问题 I come from this posts Regular Expression Arabic characters and numbers only How to match arabic words with reg exp? (didn't answer my question) I've tried ^[\p{Arabic} ]+$ and received 'Parse error', reason: 'Invalid escape sequence @ pos 3: ^[\ ▶p{Arabic} ]+$' I've also tried ^[\u0621-\u064A\s]+$ 'Parse error', reason: 'Invalid character range @ pos 7: ^[\u062 ▶1-\u064A\s]+$' I've also tried ^[\u0621-\u064A]+$ 'Parse error', reason: 'Invalid character range @ pos 7: ^[\u062 ▶1-\u064A]+$' I

How to check the validity of a GUID (or UUID) using NSRegularExpression or any other effective way in Objective-C

梦想与她 提交于 2019-12-01 02:03:28
问题 The method should return TRUE if the NSString is something like @"{A5B8A206-E14D-429B-BEB0-2DD0575F3BC0}" and FALSE for a NSString like @"bla bla bla" I am using something like: - (BOOL)isValidGUID { NSError *error; NSRange range = [[NSRegularExpression regularExpressionWithPattern:@"(?:(\\()|(\\{))?\\b[A-F0-9]{8}(?:-[A-F0-9]{4}){3}-[A-Z0-9]{12}\\b(?(1)\\))(?(2)\\})" options:NSRegularExpressionCaseInsensitive error:&error] rangeOfFirstMatchInString:self.GUID options:0 range:NSMakeRange(0,

Ensure User has entered email address string in correct format?

半世苍凉 提交于 2019-11-30 19:00:32
问题 i have a text field in Contact screen and the user need to enter email address to send me message. Whats the best way to ensure the user has entered a valid email address such as: a@b.com / net / org / co.il abc@gmail.com abc@yahoo.com etc.. Thanks 回答1: Try the following: - (BOOL) validateEmail: (NSString *) candidate { NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; //

URL Validation (Objective-C)

混江龙づ霸主 提交于 2019-11-30 09:14:10
问题 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 *urlTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", urlRegEx]; return [urlTest evaluateWithObject:candidate]; } It does not function. I think the problem is with the regular expression. 回答1: You can use + (id)URLWithString:(NSString *)URLString method of