nsregularexpression

How can I use Xcode's `Find and Replace` on Multiline blocks of text

蹲街弑〆低调 提交于 2020-01-01 17:56:51
问题 I have a large file with hundreds of blocks of text (parts of C++ method calls) that resemble the Current block below and I wish to use Xcode’s Regular Expression replacement to change each one to resemble the Desired block below, capturing values 0.89f, A name, 0.1, 0.5 and 2. Note that both blocks start and end with new Zapp and //d.p.’s to show respectively so to save myself loads of manual editing I wish to use regex search and replace. The main problem I face is the multi-line nature of

NSArray of NSRegularExpressions in swift

a 夏天 提交于 2019-12-25 18:21:09
问题 The fork here has a custom link function but the implementation in the actual code is in objective C.This is the code line and her it is printed again: - (NSArray<NSRegularExpression*>*)getRegularExpressions { return [NSArray arrayWithObject:[NSRegularExpression regularExpressionWithPattern:@"#([a-zA-Z0-9])+" options:0 error:NULL]]; } I was wondering how i could reproduce this in swift, I have already placed all of the framework code, I just need to know how to do this. 回答1: Try this func

optional capture groups with NSRegularExpressions in swift

天大地大妈咪最大 提交于 2019-12-25 07:32:06
问题 I want to have multiple capture groups that can be optional and I want to access the strings they correspond to. Something that looks/works like this: let text1 = "something with foo and bar" let text2 = "something with just bar" let regex = NSRegularExpression(pattern: "(foo)? (bar)") for (first?, second) in regex.matches(in:text1) { print(first) // foo print(second) // bar } for (first?, second) in regex.matches(in:text2) { print(first) // nil print(second) // bar } 回答1: Retrieving captured

What's a good regular expression for comment Syntax Highlighting?

南笙酒味 提交于 2019-12-25 02:01:55
问题 Say I have this text: word1 word2 " word3 //" word4 I need write a regexp for comments. My solution now is ((\/\/).*(\n)) , which results in regexp for text in "" next ((\").*(\")) 回答1: It's my solution. I know it can be better. I know about Back Reference but i don't have experience with it. NSRegularExpression *exp = [NSRegularExpression regularExpressionWithPattern:@"((@\"|\").*?(\"))" options:NSRegularExpressionDotMatchesLineSeparators error:nil]; NSArray *textArr = [exp matchesInString

PHP regular expression with optional underscore and number

谁都会走 提交于 2019-12-24 19:01:47
问题 I want a PHP regular expression that must start from 1 to 5 lower case characters, followed by an optional underscore, and then followed by 0 to 5 numbers/digits. This is my code: '/[a-z][_][0-9]/' 回答1: You're close. You need range and optional sigils: /[a-z]{1,5}_?[0-9]{0,5}/ The expression {n,m} following a character class means the class must match at least n times and at most m times. The expression ? following a character means the character must match 0 or 1 times. It's equivalent to {0

Regex for Text Within Braces

别说谁变了你拦得住时间么 提交于 2019-12-24 11:53:42
问题 I'm a total noob to regexes. I'm trying to come up with a regex that will capture text in braces. Example: {t} this text shouldn't {1}{2} be captured {3} -> t, 1, 2, 3 This is what I've tried: NSString *text = @"{t} this text shouldn't {1}{2} be captured {3}"; NSString *pattern = @"\\{.*\\}"; // The part I need help with NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:kNilOptions error:nil]; NSArray *matches = [regex matchesInString:text options

Searching for a whole word that contains leading or trailing special characters like - and = using regex in python

♀尐吖头ヾ 提交于 2019-12-24 07:38:43
问题 I am trying to know a position of a string (word) in a sentence. I am using the function below. This function is working perfectly for most of the words but for this string GLC-SX-MM= in the sentence I have a lot of GLC-SX-MM= in my inventory list there is no way to get the match. I tryied scaping - and = but not works. Any idea? I cannot split the sentence using spaces because sometimes I have composed words separated by space. import re def get_start_end(self, sentence, key): r = re.compile

Remove Empty lines using Regular Expression

落爺英雄遲暮 提交于 2019-12-23 04:46:07
问题 I'm new to iOS develoment, I have the data like this below and i want to remove all the empty lines, Please let me know what the pattern to be applied: I have used the pattern as @"(\r\n)" and replaced it with @"", but it does not work. Please help me to sort out this issue #EXTINF:-1 tvg-name="seedocs" tvg-logo="RT",RT http://rt.ashttp14.visionip.tv/live/rt-global-live-HD/playlist.m3u8 #EXTINF:-1 tvg-name="hsn" tvg-logo="hsn",HSN TV rtsp://hsn.mpl.miisolutions.net:1935/hsn-live01/_definst_

Swift - Splitting strings with regex - ignoring search string

人走茶凉 提交于 2019-12-22 11:20:29
问题 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 separators (e.g. just like the swift split function, but just with a regex expression as the separator). As an example: regex would be something like "\\\||Z|ZY" and when applied to string of "hi|thisZshouldZYbe|separated" then you would get back an

NSRegularExpression for hashtags and mentions with special characters?

泄露秘密 提交于 2019-12-21 22:09:11
问题 I'm using the following regex expression to detect hashtags and mentions in my app. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(#|@)(\\w+)" options:NSRegularExpressionCaseInsensitive error:&error]; However users within my app are allowed to use some special characters in their usernames. For example @user.name or @user_name . Spaces are not allowed. However using thins regular expression would only detect @user when it should in fact be @user.name .