Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
the cases are
compulsory '\' char at the first
followed by alphanumeric
compulsory '\' char at the last
eg:\abc\bvc\
\abc4\abc3\abc2\abc1\
Use ^ to match the begging of the string and $ to match the end of the string. Then use character class with word character.
The following allows only the alphanumeric characters
^\\[\w\\]+\\$
and then following allows any character.
^\\.+\\$
Try this:
^\\(.+\\)+$
This requires \ at the beginning and end. Also can have multiple words for a single folder name. Also allows one or more folders.
Of course there are many more valid folder paths that don't meet this regex. This regex allows characters that are not valid for folder names; not sure what all the limitations are for folder names. See this question for a discussion on valid folder names.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to read character from input and convert it to the character's int value.
The input string is in format '[character value]'.
I can do
((int)input.ToCharArray()[1])
However this does not account for escape sequences (for example \0 for hex 0x00)
Is there a way to convert a string to a character taking into account the escape sequences? (and also, is there a way to convert a string in format "[string value]" to string taking into account escape sequences as well?)
Assuming there is only one actual character that may be a literal escape-sequence, it's surrounded by single quotes and brackets. Then I guess you could use a sneaky regex escape.
var input = "'[\0]'";
var trimmed = input.Substring(2,input.Length-4);
var escaped = Regex.Escape(trimmed);
var theByte = (byte) escaped[0];
Console.WriteLine(theByte);
Demo here
Note: There are a lot of assumptions here, and there may be a better way to do this, and this may have issues I'm not aware of.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have this line:
abc cd_ef_1g fff
the 'abc' is a fixed value and always there. The fff can change.
I'm now searching for the following word, which is always second, always between whitespaces or tabs, and always after 'abc'.
cd_ef_1g
It could be with '_' or '-', or numbers.
I've searched all over, found similar results but not exactly with these conditions (using REGEX in C#).
Please help.
According to your description, this should be sufficient:
abc\s+([\w-]+)\s+fff
abc # Always before
\s+ # One or more white-space chars
([\w-]+) # One or more alphanumeric chars ('-' also included)
\s+ # One or more white-space chars
fff # Always after
The captured group is the word sought after.
Demo
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am trying to read only files from a location which has no "test" and "dummy" in the file name by using regular expression.
For Example the file path has below files.
file1.csv
file2.txt
20170811_test_1.dat
1_dummy_20170811.dat
Here I need to find file1.csv and file2.txt and exclude all other files which has test or dummy (can be of any case lower/upper).
You can try this :
^(?!.*test|.*dummy).*$
^ : declaring the begining of the line
?! : doesn't contain test OR (|) dummy, even not at the begining (.*)
.* : match all characters
$ : declaring the end of the line
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I've got the following string all over my code:
languageService.getString("string_from_key");
Now I want to replace "string_from_key" (with the quotation marks) with KeyClass.string_from_key.
I am struggling with the RegEx in Visual Studio 2015 to search and replace the mentioned strings all over the code. string_from_key is a changing value, thats why RegEx. Thanks in advance.
Try matching more, and then using replacement parameters:
Search:
languageService.getString\("(\w+)"\);
Replace:
languageService.getString\(KeyClass.$1\);
Double quotes are not metachars in regexes, but parentheses are. \w+ will match more or more "word" characters, but that includes underscores (because history) so is very useful for identifiers.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Good Afternoon,
I would like a regex to validate if the user typed two names or more and not only the first name, as in this example:
Ex: Fabrício (no match)
Ex:
Fabrício Oliveira (match)
Fabrício Oliveira Xavier (match)
Note: The expression must contain accents
Here's a Regex that only relies on a whitespace separator:
^\S+(\s\S+)+$
It makes these assumptions:
No name has a space, tab, or newline in it
Names are separated by exactly one space, tab, or newline
* this is based on #juharr's comment but with the parentheses to allow more than two names.
Edit: You can play around with this Regex here https://regex101.com/r/nS3hN8/1
Edit2: Added the beginning and ending anchors to the regex
Try this regular expression which matches two any length words separated by a space:
new Regex(#"\w+ \w+");
Really you could just use this:
if (Regex.Match(stringname, #"\w+\s\w+").Success)