Need help with a file path validation regular expression - regex

I am using a RegularExpressionValidator in visual studio and I am struggling to create the correct regular expression for my needs. Here is what I want:
The input can contain any character except <>:"/|?*
Also, the input can not contain two backslashes in a row
So, your\mom would be ok but your\\mom would fail as would your*mom
The closest I have come at this point is something like
^(?=.*[^<>:"/|?*])(?:[^\\]+|\\(?:$|[^\\])).{0,100}$
but it doesn't work.

^(?!.*\\\\)[^<>:"/|?*]*$
should do it.
(?!.*\\\\) asserts that there are no two backslashes in a row in the string.
[^<>:"/|?*]* matches any number of characters except the ones inside the character class.
That is, unless you're talking about the regex features of Visual Studio (the IDE environment itself) which has a wildly nonstandard regex flavor.

Related

Wildcard in Word 2013 to match zero or more whitespaces

What is the analog of regular expression's * modifier in Word 2013 wildcards?
In Word 2013 Find tool with wildcards enabled, apparently 0 is not a valid number as the number of matches. For example, if you type in the search box
fe{1,2}d
it will match fed and feed. However,
fe{0,2}d
will just produce an error message. What is the correct expression to match fd, fed, feed, feeed, etc.?
My motivation is to match a specific text when it is in a paragraph alone (i.e., surrounded by paragraph marks ^13) but with a possible whitespaces after it:
^13hello world {0,}^13
which just produces an error message. I did not find any solution without enabling wildcards, but even with wildcards enabled I can't get it working.
Similarly,
^13hello world #^13
matches one or more spaces, but I need zero or more.
I don't believe Word has ever had an equivalent for the zero-or-more operator, so while I haven't checked in Word 2013, I wouldn't expect to see it there either. (This page is old, but as far as I know it's still pretty authoritative on wildcard searching in Word: http://word.mvps.org/faqs/general/usingwildcards.htm)
In general, I would suggest doing two searches, one without the character and one using the 1-or-more operator.
ETA: Removed bad wildcard search.

visual Studio 2010 regular expressions for 'Find In Files'

I have look at the many stackoverflow posts concerning VS regular expressions and read the Microsoft page concerning regular expressions but still cannot determine where I am going wrong.
Microsoft VS regex
I want to find all lines which include the word, attribute, but which are not comment lines (do not contain the // symbol).
I have tried using the regular expression
~(^ *//).*attribute.*
meaning:
~(^ *//) --> exclude lines which begin with '//' preceded by zero or more spaces
.* --> match any character zero or more times
attributes --> match the word attributes
.* --> match any character that comes after the word attribute
I have tried several other regular expressions with about the same amount of failure. I am wondering if anyone can spot something obvious that I am not doing.
I also gave the below a try:
~( *//).*attribute.* (thinking maybe the carat was being taken as a literal instead of special)
~(//).*attribute.* (thinking maybe the * was being taken as a literal instead of special)
~(//)attribute (imminent failure but will try anything)
\s*~(//).*attributes.*
I saw quite a few posts suggesting to use the find command in batch. This can be done, but I would prefer to have the ability to double click on the findings so that the file will be opened and already scrolled to the correct location.
How about this one.
^(?=.*attribute.*\n)(?!.*//).*

RegEx for for string that has bezier<somestring>Path

I have a large file in xCode that contains numerous occurrences of bezierPath (ie bezier456Path). What I'd like to do is come up with a regular expression for this string so I can replace it simply with the string "bezierPath". I've tried things like bezier\w*Path to no avail. Does anyone know what I could use to search for a string like this?
\w is for word characters. Based on your example, you need to search for digits (\d):
bezier\d+Path
Also, since your replacement string is bezierPath, there is no point in using * (i.e. zero or more), since that would include replacing bezierPath with itself. Therefore, you should use + (i.e. one or more), instead.
I don't have access to xcode, but can't you use Find with
(bezier.*?Path)
and then use Replace with the path that you want, so in this case just bezierPath

REGEX to extract word connected to nearest semicolon?

I'm attempting to extract a series of data values from a text file.
The values are in the format: <MODIFIER NAME1 VALUE; MODIFIER NAME2 VALUE;>
For the purposes of the current task that I have, I only care about extracting the VALUE that is situated next to each semicolon. What would the REGEX command look like that would isolate each of these VALUES (preferably so that I backreference all values in the replacement part of my processing.) I believe that ^(.*?); is somehow used, but I'm not seeing how to isolate only the word that is attached to the semicolon in a group for backreference use.
The exact syntax depends on the language, but the following regex should do it
"(\w+);"
I used the c# syntax. In other languages, the syntax might change a bit, but the actual regex remains the same.
where \w means any letter(it also includes 0-9 and '_), and the parenthesis signify that you capture the group inside.
if you want only letters, you can change the \w to [a-zA-Z] (again, different languages may or may not have different syntax for this)
I use This reference to reference my c# regex syntax. If you're using another language, that will also have something similar somewhere.

How do I convert strings in code to uppercase in Visual Studio?

I'm trying to convert all character strings that match a particular regex in a file to uppercase, but I can't find the syntax to specify that within the 'Find and replace' window in Visual Studio. Is it possible to do this using the Visual Studio regex?
As JaredPar has expained, this cannot be done using a generic regular expression search/replace. However, I guess you should be able to do this using a macro.
It's not possible to do this as a generic replacement using Visual Studio regular expressions. It is possible to re-use the captured text as part of a replacement string using the \n escape sequence where n represents the nth group of captured text. However the regex language only supports limited modifications on this text (mostly justification changes). It doesn't allow you to change case.
Here is a link to the Visual Studio regex language
http://msdn.microsoft.com/en-us/library/2k3te2cs(VS.80).aspx
press alt + 'e' when the find window has focus to enable "regex" searches.
naturally, you can't 'program' a set of replacement options to insert based on what is found. Each replacement set would require one pass.