I am reading a file by line and need to extract latitude and longitude from it.
This how lines can looks:
DE 83543 Rott am Inn Bayern BY Oberbayern Landkreis Rosenheim 47.983 12.1278
DE 21147 Hamburg Hamburg HH Kreisfreie Stadt Hamburg 53.55 10
What's for sure is, there are no dots surrounded by digits except for the ones representing the doubles.
Unfortunately there are Values without a dot, so it's probably best to check for numbers from the end of the String.
thanks for your help!
Hey Everyone,
I need to search a bunch of files for anything that contains either "tblPayment" or "tblInvoice"
I also want to match any tables named "tblPaymentMethod", "tblInvoiceItem", "tblInvoicePayment"
Anybody care to help me out with how to write a regular expression for this?
Thanks again!
I'd like to quickly hone in on what failed in a build log output that is nearly 5k lines long, using Notepad++ as my editor for the file. Notepad++ has the nice ability to specify regular expressions, so I am wondering if there is a way to not match:
Compile complete -- 0 errors, 0 warnings
but to match, for example:
Compile complete -- 1 errors, 0 warnings
Compile complete -- 100 errors, 0 warnings
where the match would be (1 or more) errors.
If this isn't possible, I will probably just write a quick line-by-line parsing tool instead, but I was hoping someone on StackOverflow could whip out a regular expression in the same amount of time - I'm definitely not proficient enough with regular expressions to be able to write one for my needs in a short amount of time.
This is probably a really basic question, but I can't find any answers. I need to match a string by either one or more spaces OR an equals sign.
When I split this string: 9 x 13 = (8.9 x 13.4) (89 x 134)
with ( +) I get:
part 0: 9 x 13 = (8.9 x 13.4)
part 1: (89 x 134)
When I split it with (=) I get:
part 0: 9 x 13
part 1: (8.9 x 13.4) (89 x 134)
How can split by BOTH? Something like: (=)OR( +)
Edit:
This does not work(=)|( +)
Test it here: http://myregexp.com/ under "split".
var r = /\d/g;
var a = r.test("1"); // will be true
var b = r.test("1"); // will be false
console.log(a == b); // will be false
Please explain to me why the result of r.test("1") alternates with each call?
I was able to work around the issue I was having by removing the g modifier. However I would still like to understand why this happens.
What is your opinon about following regexes - is it correct?
To find element with spcific and required attribute
"<(" + elem_name +
")(\s+(?:[^<]?\s+)" + attr_name +
"\s*=\s*(['\"])((?:(?!\3).))\3[^<])(.*?)"
To find element with spcific but optional attribute
"<(" + elem_name +
")(\s*|\s+(?:[^<]?\s+)(?:" +
attr_name +
"\s*=\s*(['\"])((?:(?!\3).))\3)?[^<])(.*?)"
Pleas not another answer "use existing xml parser". Question is - are the regexes proper or not? This is specific situation - C language in embedded system and xml is not well-formed (cannot be fixed - does not depend on me). Xml have specified schema and no problem with namespaces etc. exists.
I have login view that takes a LoginPageViewModel:
public class LoginPageViewModel : PageViewModel
{
public string ReturnUrl { get; set; }
public bool PreviousLoginFailed { get; set; }
public LoginFormViewModel EditForm { get; set; }
}
which is rendered in the view. When a user tries to log in I only want to post the LoginFormViewModel (Model.EditForm) to the controller:
public ActionResult Login(LoginFormViewModel loginDetails)
{
//do stuff
}
Using Html.TextBox I can specify the name of the form field manually 'loginDetails.UserName' and post back to the controller and everything works.
@model Web.Controllers.User.ViewModels.LoginPageViewModel
@using (Html.BeginForm()){
@Html.Hidden("loginDetails.ReturnUrl", Model.ReturnUrl)
@Html.LabelFor(x => x.EditForm.UserName, "User Name:")
@Html.TextBox("loginDetails.UserName", Model.EditForm.UserName)
@Html.ValidationMessageFor(x => x.EditForm.UserName)
.....
But what I want to do is to use the staticaly typed helper, something like:
@Html.TextBoxFor(x => x.EditForm.UserName)
But I'm unable to get this to work.
Are you only able to post back the same model when useing the strongly typed helpers? Is there something I'm missing on this? Intellisense doesn't seem to give any clues such as a form field string.
Is it possible to use a regular expression to get filenames for files matching a given pattern in a directory without having to manually loop through all the files.
I have some text; I want to extract pairs of words that are not separated by punctuation. Thi is the code:
//n-grams
Pattern p = Pattern.compile("[a-z]+");
if (n == 2) {
p = Pattern.compile("[a-z]+ [a-z]+");
}
if (n == 3) {
p = Pattern.compile("[a-z]+ [a-z]+ [a-z]+");
}
Matcher m = p.matcher(text.toLowerCase());
ArrayList<String> result = new ArrayList<String>();
while (m.find()) {
String temporary = m.group();
System.out.println(temporary);
result.add(temporary);
}
The problem is that it skips some matches. For example "My name is James", for n = 3, must match "my name is" and "name is james", but instead it matches just the first. Is there a way to solve this?
How can I apply multiple regexs to a single string?
For instance, a user inputs the following into a text area:
red bird
blue cat
black dog
and I want to replace each carriage return with a comma and each space with an underscore so the final string reads as red_bird,blue_cat,black_dog.
I've tried variations in syntax along the lines of the following so far:
function formatTextArea() {
var textString = document.getElementById('userinput').value;
var formatText = textString.replace(
new RegExp( "\\n", "g" ),",",
new RegExp( "\\s", "g"),"_");
alert(formatText);
}
So I have defined variables in such a way in my file:
public static final String hello_world = "hello world"
public static final String awesome_world = "awesome world"
public static final String bye_world= "bye world"
I have many declarations like that.
Is it possible to format them as(All '=' in a line):
public static final String hello_world = "hello world"
public static final String awesome_world = "awesome world"
public static final String bye_world = "bye world"
I can't even think of a way to do it. Any kind of help is appreciated.
P.S If it matters, I use sublime text 2.
I am developing a ebook reader app. I have the .ePUB file for the entire ebook where in each topic of the ebook is a html file. I want to implement the search functionality in the app. I am using NSRegularExpression class for searching. Please consider the following html code:
<temp> I am temp in tempo with temptation </temp>
Say for example in the above html code I just want to search for the word temp. Now in above code temp is appearing 5 times - <temp> </temp> temp tempo temptation. I am looking for a regular expression where I can only extract the whole word "temp". I don't want to consider the word temp in the html tags <temp> </temp>. I also don't want the word tempo and temptation to be considered.
Thanks in advance
Is it possible to do a regex replace on all IMG tags that are unclosed? If so, how would I identify:
<img src="..." alt="...">
...as a potential canidate to be replaced?
= <img src="..." alt="..."/>
Update: We have hundreds of pages, and thousands of image tags, all must of which must be closed. I'm not stuck on RegEx -- any other method, aside from manually updating all IMG tags, would suffice.
End of line anchor $ match even there is extra trailing \n in matched string, so we use \Z instead of $
For example
^\w+$ will match the string abcd\n but ^\w+\Z is not
How about \A and when to use?
I am having a find a replace in a bunch of RTF documents, The basic pattern I need is
\{(?:\\\*)?\\field\\fldlock\{\\\*\\fldinst ?MERGEFIELD ?((?:\\.*?)?[\w\[\]]+?)(?:\\.*?)?\}(?:\{\\fldrslt\})?\}
However I then found out there could potentialy be a newline before each slash, so it turned in to this.
\{(?:\s*\\\*)?\s*\\field\s*\\fldlock\s*\{\s*\\\*\s*\\fldinst\s*MERGEFIELD\s*((?:\\.*?)?[\w\[\]]+?(?:\s*\\.*?)?)?\s*\}(?:\s*\{\s*\\fldrslt\s*\})?\s*\}
But then I hit this it fails
fees totaling $\protect {\field\fldlock{\*\fldinst MERGEFIELD ENTEROUTSTANDINGVETERINARYF
EES}}\plain\f0\fs24\prot
Is there way have to have it match a new line anywhere in the search too without adding (?:\r?\n)? everywhere?
EDIT
To clear up confusion on the new lines. I need to keep the newlines in the document, I only want to remove the newlines if they are inside my match, so in the final example I posted it should replace
fees totaling $\protect {\field\fldlock{\*\fldinst MERGEFIELD ENTEROUTSTANDINGVETERINARYF
EES}}\plain\f0\fs24\prot
with
fees totaling $\protect ENTEROUTSTANDINGVETERINARYFEES\plain\f0\fs24\prot
How can convert the below youtube urls
$url1 = http://www.youtube.com/watch?v=136pEZcb1Y0&feature=fvhl
$url2 = http://www.youtube.com/watch?feature=fvhl&v=136pEZcb1Y0
into
$url_embedded = http://www.youtube.com/watch/v=136pEZcb1Y0
using Regular Expressions?
Hi everyone. I'd ideally like a vim answer to this:
I want to change
[*, 1, *, *] to [*, 2, *, *]
Here the stars refer to individual characters in the substring, which I would like to keep unchanged. For example
[0, 1, 0, 1] to [0, 2, 0, 1]
[1, 1, 1, 1] to [1, 2, 1, 1]
If people know how to do this in perl or python or whatever, that would be equally good.
Cheers
I need a regular expression with the following needs:
the string is alphanumeric and have exactly 6 characters in the first half followed by hyphen(optional) followed by optional 4 characters:(cannot have more than 4 characters in the second half)
so any of the following is valid
11111A
111111-1
111111-yy
yyyyy-989
yyyyyy-9090
i thought this expression /[a-zA-Z0-9]([-])?[a-zA-Z0-9]{5,10}$/; should work but i m unable to get it working correctly.
Any help will be appreciated,
This my simple data : <table></table><table></table><table>aaa</table>
how to match <table></table><table></table>***<table>aaa</table>***
it should be return <table></table><table></table>