Reply
Thread Tools
Posts: 10 | Thanked: 0 times | Joined on Feb 2009
#1
Hello fellow developers
I am creating an app for tracking car (fueling, services, trips eg) and I need to validate input user gives me through gtkentry.
I have managed to create needed gregex patterns after a day of work just to find out that glib on Diablo is 2.12 and GRegex is included since 2.14.
So my question is if there is some way to validate entry with regular expressions other then GRegex class or there is a way to install GLib 2.14 or higher, or how should I validate user entry.
If you find this question newbee it's because I have no experience writing linux code and I would be thankfull for your advise.
ps. I using c and glib
Johnnnie
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#2
There doesn't look to be any obvious alternatives (you can find the GLib documentation at http://library.gnome.org/devel/glib/2.12/). Depending on the patterns you're trying to parse, the "Glob-style pattern matching" may work, otherwise you're down to low-level string functions (which gets complicated very quickly).
 
Posts: 10 | Thanked: 0 times | Joined on Feb 2009
#3
Hi Rob1n
thanks for an answer and can you point me to some "Glob-style pattern matching" documentation or examples because I have already "googleed" this and didn't find any helping info
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#4
The documentation is on the page I gave you above (http://library.gnome.org/devel/glib/...-matching.html takes you directly). This would look to only give a TRUE/FALSE as to whether a string matches a pattern though, so may not be much help. It could present a starting point for string functions (http://library.gnome.org/devel/glib/...Functions.html) though (i.e. check which general format it matches before trying to pull out the relevant values).
 
Posts: 236 | Thanked: 223 times | Joined on Oct 2009 @ NE UK
#5
Can you use pcre ? It seems to exist on the diablo repo at http://repository.maemo.org/pool/diablo/free/p/pcre3/
 
Posts: 10 | Thanked: 0 times | Joined on Feb 2009
#6
Originally Posted by kwotski View Post
Can you use pcre ? It seems to exist on the diablo repo at http://repository.maemo.org/pool/diablo/free/p/pcre3/
I suppose so but it will require some digging
in that case I have another question
suppose I have input like this:
some text "foo bar" and I would like to match just some text and not the text in quotation marks
can you help me with proper regex because I am kind of lost
ps I have regex which will extract text in "" "[\w\s]+"
but I do not know how to do opposite
thank you very much
 
Posts: 236 | Thanked: 223 times | Joined on Oct 2009 @ NE UK
#7
Well, I'll admit I haven't used libpcre in a program, but it stands for "perl compatible reg. ex.", and I have done a bit of perl, so I hope you won't mind if I answer based on my understanding of perl

This really depends on what you want to do, BTW!

Anyway, suppose we have some text "foo bar" some other text

If I match against the regex:
Code:
^([^"]*)"[^"]*"(.*)$
then after the match, $1 contains 'some text ' and $2 contains ' some other text'. ($1 and $2 are the first and second matched substrings).

If there are less than 2 "" quotes, though, you won't match at all, and so $1 and $2 will be empty.

Also, if there's more than one set of quotes, then the second set will appear in $2, so a match against 'some "text" some "other" text' would set $1 to 'some ' and $2 to 'some "other" text', which might not be what you want.

If you just want to match all text (possibly none) up to the first quote, then match against:

Code:
^([^"]*)
After this, $1 would contain 'some text ' (note the trailing space!)

(the [^blah] is a 'negative character class' that matches against anything but (in that case) the letters b, l, a, h. Or in the example above, anything that's not a ".)

When validating user input, I've found, where the user has unconstrainted ability to supply a string, it's better to be cautious and keep things simple. You might want to consider just rejecting their input until they supply something you're happy with.

e.g: does it match

Code:
^[\w\s]+$
?

If yes: make sure it's not too long then process it.. If no: tell them no funny characters are allowed and try again

http://regexkit.sourceforge.net/Docu...ntax.html#SEC1 for the pcre syntax..

http://regexkit.sourceforge.net/Docu...cre/index.html for the full docs.

Hope that's enough to get you going..

Last edited by kwotski; 2009-12-11 at 23:31.
 
Reply


 
Forum Jump


All times are GMT. The time now is 23:10.