Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 24 results for
regix
- Page 1
Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by scheppy
Hey Guys, So I have a JTextfield in the cells of 1 of the columns in my JTable I want to allow only numbers and up to one dot/period. Doesant need to contain a period. The persiod can be anywhere except at the end of the number. 1 ok .1 ok 1.1 ok 1.1.1 not ok 1. not ok This is my expression in my code Currantly it allows only…
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by Reverend Jim
What you want is 0 or more digits `^[0-9]*` followed by 0 or 1 decimals `\.?` followed by 1 or more digits `[0-9]+$` which gives you ^[0-9]*\.?[0-9]+?$ Coincidentally, I had just posted a regular expression tester [vb.Net project ](https://www.daniweb.com/programming/code/516679/vb-net-regular-expression-tester) which is …
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by scheppy
So this doesant allow numbers only letters.... and more than 1 decimal point....?? I dont know, I put it in like this maybe im doing it wrong. private JTextField createTextField() { JTextField field = new JTextField(); ((AbstractDocument) field.getDocument()).setDocumentFilter(new DocumentFilter() {…
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by Reverend Jim
>So this doesant allow numbers only letters.... and more than 1 decimal point....?? How did you get that from what I posted? What I gave you evaluates as ![2018-07-16_173811.jpg](/attachments/small/3/1bfd9615b136eb0f1f2fa7c2dd0318c6.jpg "align-center") I see you entered the pattern as `^[0-9]*\\.?[0-9]+?$`. I don't use …
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by scheppy
If I take away 1 of the backslashes, Then I get an error, "Illegal escape character" I need them both to not get any errors,
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by JamesCherrill
In a java string literal the backslash is an escape char, so to enter an actual backslash you need to code two backslashes
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by Reverend Jim
I guess java doesn't have a `raw string` capability like python. I used [Regexper](https://regexper.com/) to generate the graphic.
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by scheppy
Anyone else have any input? Tried a bunch of differant solutions, None of them work :( Thank you very much so far. Keep in mind if the above wouldve worked, it wouldent of allowed a period/dot at the begginging of the string, I do need this.
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by Reverend Jim
I can't test it in Java but it works the way you want in vbScript and vb.Net. My pattern clearly states "zero or more digits before a decimal point".
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by rproffitt
@all. I tried to use some online Java regex tools and it appears something is indeed different about Java. (duh?)
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by scheppy
I love reguler expressions till somthing like this happens :(
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by Reverend Jim
I tried to account for differing dialogs by using `[0-9]` (which is standard) as opposed to `\d` (which is not) but, oh well.
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by scheppy
Any other Idea's Reverand?? You may just be able to save me :)
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by ddanbe
When I use a regular expression(rarely) I use a Regex class. [Sample code in C# and VB](https://msdn.microsoft.com/en-us/library/43122zyz(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2). Don't know if something similar exists in Java. But I doubt if no one has developed a library for it.
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by Reverend Jim
Since I do not use java and can't test it locally, I suggest that you work on just the regular expression and test it in one of the free, online java regex testers available. Google `java regular expression tester` and pick one of the several available.
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by JamesCherrill
> Don't know if something similar exists in Java How could you doubt it? https://docs.oracle.com/javase/10/docs/api/java/util/regex/package-summary.html
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by scheppy
I'm Still having trouble figuring this out and for the life of me cant do it, Anyone have anything? I want to allow only numbers and up to one dot/period. Doesant need to contain a period.
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by Reverend Jim
I gave you the regex that does what you want. Presumably your problem is translating it into a string that will work in java for which I am unable to help you. Is there a java person out there who can give it a try?
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by ddanbe
Perhaps [this](https://stackoverflow.com/questions/2673855/java-equivalent-of-cs-verbatim-strings-with) can help.
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by JamesCherrill
Hi guys, mind if I join in? I tried `^[0-9]*\.?[0-9]+?$` in Java - just needed to double up the backslash for a Java literal. Works OK for me. Maybe the problem is in how the regex is being used. The `replace` method in the earliest code doesn't use regexs. The `replaceAll` in the later code does use a regex, but the way it works is to …
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by scheppy
I have an above feeling that mve code is correct, it is just working backwords, im not sure, everything online does the opposit that I want, They say it removes letters, it allows numbers and not letters.... Just some background, This is filtering a JTextfield as a user is typing inside of a jtable.
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by Reverend Jim
If it's being used interactively (as in while the chars are being typed) then it can't work. For example, to enter the number `123.45`, each of the first three digits would be allowed by the pattern. However, as soon as the `.` is entered it would be flagged as invalid because a number cannot end with a `.`. The user would have to enter `12345` and…
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by JamesCherrill
> mve code is correct, it is just working backwords, ??? This is what we call "denial" and it's never going to help. It's not correct because it doesn't do what you want, and a root cause of that is because you are trying to do the wrong thing in the first place. RJ is right. Full validation on a keystroke by keystroke basis …
Re: Reguler Expression (regix) problems
Programming
Software Development
5 Years Ago
by JamesCherrill
... but I still don't understand why you don't just use the Swing built-in classes, eg JFormattedTextField field = new JFormattedTextField(NumberFormat.getNumberInstance());
Search
Search
Forum Categories
Hardware/Software
Programming
Digital Media
Community Center
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Forums
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2024 DaniWeb® LLC