I would appreciate if any one has RegEx Pattern Match Code to be used in Powerbuilder application.
Natively, I'd be reluctant to call this "RegEx", but if you have rudimentary pattern matching needs, Match() is the PowerScript function that does this. It has basic operators, but will only tell you if you have a match, not where in the target string.
If you need something more robust than that, even if it hadn't already been mentioned, I'd point you towards PbniRegex.
Good luck,
Terry.
If using PB.NET then you can use .NET framework assemblies that have robust RegEx functionality. If not then maybe what Terry mentioned about PBNIRegex, for which I don't have any experience with.
Related
I wrote this regex to find absolutely all kinds of comments in file, but it detects http:// also because of (//.*).
(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*)|(<!--[\s\S]*?-->)
How to modify this regex to not to find http:// etc? Do you think that it's optimal regex for this purpose? If not what do you suggest?
Looks like a lot of fun there. :) How about using the negative lookbehind technique with regex if it is supported with the setup you're using. Instead of:
//
use:
(?<!:)//
I'm lousy at regular expressions but occasionally they're the only thing that's the right solution for a problem.
Is there something in the .NET framework that allows you to input an unencoded string and get a pattern from it? Which you could then modify as required?
e.g. I want to remove a CDATA section that contains a file from some XML but I can't work out what the right pattern is for <![CDATA[hugepileofrandombinarydataherethatalsoneedstogo]]> and I don't want to ask for help each time I'm stuck on a regex pattern.
Such tools exist, google by "regex generator".
But, as suggested in comments, better learn regex. Simple patterns are easy. Something like <!\[.*?]]>
in your case.
There are Regex Design tools like expresso...
http://www.ultrapico.com/expresso.htm
It's not perfect but as there is no suitable .Net component the text to regex page at txt2re.com is the best I've seen for those people who occasionally need to build a regex to match a string but don't have the time to relearn regex each time they want to use one.
I tried to make regex syntax for that but I failed.
I have 2 variables
PlayerInfo[playerid][pLevel]
and
Character[playerid]
and I want to catch only the second variable,I mean only the world what don't contain PlayerInfo, but cointains [playerid]
"(\S+)\[playerid\]" cath both words and (\S+[^PlayerInfo])\[playerid\] jump on some variables- they contais p,l,a,y ...
I need to replace in notepad++,all variables like Text[playerid] to ExClass [playerid][Text]
Couple Pluasible solutions.
List item
Notepad has a plugin called python script. Running regex from there
gives full regex functionality, the python version anyway, and a lot
of powerful potential beyond that. And I use the online python regex tester to help out.
RegRexReplace plugin helps create regex plugins in Notepad++, so when you do hit a limitation, you find out a lot quicker.
Or of course default to your alternate editor (I'm assuming you have
one?) or this online regex tool is absolutely amazing. You
can perform the action on the text online as well.
(I'd try to build a regex for you, but I'm a bit lost as to what you're looking for. Unless the Ivo Abeloos got it. If you're still coming up short, maybe a code example along with values displayed?)
Good luck!
It seems that Notepad++ support negative lookbehind since v6.
In notepad++ you could try to replace (.+)\[(.+)\] with ExClass\[\2\]\[\1\]
Try to use negative lookbehind.
(?<!PlayerInfo)\[playerid\]
EDIT: unfortunately notepad++ does not support negative lookbehind.
I tried to make a workaround based on the following naive idea:
(.[^o]|[^f]o)[playerid]
But this expression does not work either. Notepad++ seems to fail in alternative operator. Thus the answer is: it is impossible to do exactly what you want. Try to solve the problem in other way or use alternative tool.
What are the common ways to verify the given regex pattern works well of the given scenario and check the results ?
I would like to know in general , not in the particular programming language and what is the best way to learn about writing regular expression ?
Books: Mastering Regular Expressions is the definitive guide to regular expressions. The Regular Expressions Cookbook is said to be lighter and more easily applicable.
Sites: Friedel's companion site is a good start. Regexlib is a source of idioms and patterns.
Software: RegexBuddy is a good, per pay, regex verifier.
I've used this resource when learning: http://www.regular-expressions.info/ and found myself going back there whenever there was something I needed to remember. It's very useful for learning and covers the basics very well. They also have various links to programs which can be used to verify regular expressions.
This is not a "real" verification, but RegexBuddy allows you to verify that your regex does what you expect it to do on any sample data you provide. It also translates the regex into an English description that can help to figure out mistakes. Plus, it knows all major regex flavors and can translate regexes between them.
For testing regular expression you can use RegEx Test tools like one below :
http://www.regextester.com/
To know more about how to learn regular expressions please check following SO threads :
Learning Regular Expressions
How to master Regular Expressions?
https://stackoverflow.com/questions/465119/how-do-i-learn-regular-expressions-closed
RAD Rexexp designer is a great tool
Set up an automated test using your tools of choice (because regex implementations vary from language to language and library to library) which applies the regex to a variety of both matching and non-matching inputs to verify that you get the correct results.
While RegexBuddy and the like may be helpful for initially creating the regex (or may not; I've never used them), you will still need to maintain it, just like any other code. When that time comes, it's vastly preferable to have a test script that will run through all your old test inputs (plus the new ones which created the need for the change) in a matter of seconds rather than having to sit on a website for tens of minutes, if not hours, trying to remember all your test inputs and manually re-run them to make sure you didn't break anything.
I am looking for a wildcard string match API (not regex match). I cannot use anything other than Win32 APIs.
There is PathMatchSpec - but handling is specialized for files, so results might not be what you expect if you need general wildcard matching.
Otherwise, you should probably go with an RegEx, as Pavel detailed.
[edit]
I incorrectly assumed PathMatchSpec shares the properties of FindFirstFile/FindNextFile. I've ran a few tests - it doesn't. So it looks like the best candidate.
Strange that so many years passed and nobody gave you this answer:
There is a WIN32 API that does exactly what you're looking for. (I found it searching in the MSDN for "wildcard")
It's name is SymMatchString. It sits in DbgHelp.dll which is part of the operating system.
Put a CriticalSection around the API call if your app is mulithreaded!
The API that FindFirstFile uses internally for wildcard matches is probably FsRtlIsNameInExpression.
Elmü
The easiest thing would be to just convert your glob pattern to a regex, by the following rules:
* becomes .*
? becomes .
Any of \|.^$+()[]{} are escaped by preceding them with \
This is partly true.
Following rules are inducted from DIR behaviour in XP+ Command Prompt:
* is the same as *.* and becomes regex .+
? becomes regex .? unless followed by a non-wildcard
? not followed by a wildcard becomes regex .
*. means "without extension", and becomes [^.]+$
The FindFirstFile and FindNextFile APIs do wildcard matches, but only against filenames.
You can't use anything but Win32? What about STL or CRT? Are you using Boost?
Without the Win32 API restriction, I would recommend using the code from some open-source project. Another option would be to translate the glob into a regex, which I believe can be done with a regex replace operation.
edit: First google match is the PHP code:
http://cvs.php.net/viewvc.cgi/php-src/win32/
If you're after a simple wildcard compare (globbing), some people have written their own, including this one (which we use in our code)
WHat exactly is your requirement? Are you just looking to use the '' symbol to match 0 or more characters or are you planning on using the '?' symbol as well. If it is just '', do you need to look for a, a, ab, ab*c, etc type patterns? If your requirement is limited, you could easily get away with the C++ runtime library's strstr function.