Extracting Address' from police reports [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm currently working on a program that would be searching through medium-large strings and pulling out addresses so they can then be geocoded.
An example of what I had was:
private void cardCheck()
{
cardCount = mobjEntity.CardCount;
for (int i = 0; i < cardCount; i++)
{
card = mobjEntity.Card[i];
if (card.Text.Contains(" STREET ") ||
card.Text.Contains(" Street") ||
card.Text.Contains(" street") ||
card.Text.Contains(" ST ") ||
card.Text.Contains(" St ") ||
card.Text.Contains(" st "))
{
}
}
}
I'm not very good at regex and I was hoping one of you regex wiz' could show me a useful link for testing/learning regex.
I have written what I have above for every street type and it's very tedious and I still don't even know what to do from there.
This is an Ideal Input Output:
Input:
On Friday, April 9, 2010, at 9:45 a.m., I, Officer Janice Ruiz, was dispatched to 2170 Powell Street to investigate a burglary. I met with Frank Gaines, the homeowner who had reported the burglary.
Output:
2170 Powell Street

Have you tried using a regular expression to search the text? A quick Google search returns several RE's that may work for you. Here is one example:
\d{1,3}.?\d{0,3}\s[a-zA-Z]{2,30}\s[a-zA-Z]{2,15}
Here is a proof of concept: https://regex101.com/r/dH3jJ8/1

Related

REGEX specific word from Name [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to figure out regex for wrongly formated names where the user has entered in the name and the relationship as one value, for example
[Son of Joseph Joestar ] => s/o. Joseph Joestar
the problem is since there was no validation, the users entered different variations like
s/o , s/, s/Joseph... , etc
this is so far I have gotten
^(s\/o.)(S\/o.)(s\/o)(S\/o)(s\/)(S\/)\w+
the relation is at the beginning or at the start, and after that is the name
there are 3 more cases Daughter(D/o.), Wife(W/o.), Father(F/o.)
I want to know the corresponding REGEX to filter out the relation prefixes
Thank You In advance
Maybe start with something like that
string foo = "s/o. Joseph Joestar";
// Look (and capture) for SDWF followed by "/" and
// EITHER "o" and maybe "." and maybe a white space
// OR we look ahead (?= ) and see a Upper wordchar followeed by lower word chars.
// look ahead because we do not want to have anything to do with this when replacing
string bar = Regex.Replace(foo, #"^([sSdDwWfF])/(o\.?\s?|(?=[A-Z]\w+))", match =>
{
string relation = match.Groups[1].Value.ToUpper() switch
{
"S" => "Son of",
"D" => "Daughter of",
"F" => "Father of",
"W" => "Wife of",
_ => throw new Exception("Oops")
};
return $"{relation} ";
});

write regex c # [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
write a regular expression for taxi numbers in Belarus
1)region code (a digit from 1 to 7);
2)three uppercase Latin letters. For the `7' region (Minsk), the combinations TAX, TBX, TEX are used, for other regions, only TAX, TBX are currently in use;
3)a single space;
4)four-digit number from 1 to 9999, with leading zeroes.
You almost got it. Try something like
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string text = "1TAX 1234\r\n7TEX 9876\r\n5TEX 9876\r\n4TBX 9876";
string pattern = #"^(?:(?:[1-6]T[AB]X)|(?:7T[ABE]X))\s\d{4}";
Regex r = new Regex(pattern, RegexOptions.Multiline);
foreach (var m in r.Matches(text))
{
Console.WriteLine("> {0}", m.ToString());
}
}
}

Split string data Using Regex in c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Hi I have String Like Following
string str=SCAN: SITE: http://www.vividinfotech.com SCAN: DOMAIN: www.vividinfotech.com SCAN: IP: 66.55.155.156 SYSTEM: NOTICE: Running on: ApacheRECOMMENDATIONS: 0: Security Header: X-XSS-Protection MissingRECOMMENDATIONS: 0: We did not find the recommended security header forXSS Protection on your site.
I need split the like SCAN and RECOMMENDATIONS datas
as follows :
SCAN:
1.http://www.vividinfotech.com
2.DOMAIN: www.vividinfotech.com
3.IP: 66.55.155.156
is there any way do this
Simple way to do this is using the following regular expression:
string str = "SCAN: SITE: http://www.vividinfotech.com SCAN: DOMAIN: www.vividinfotech.com SCAN: IP: 66.55.155.156 SYSTEM: NOTICE: Running on: ApacheRECOMMENDATIONS: 0: Security Header: X-XSS-Protection MissingRECOMMENDATIONS: 0: We did not find the recommended security header forXSS Protection on your site.";
Match m = Regex.Match(str, #"SCAN: SITE: (.*)SCAN: (DOMAIN:.*)SCAN: (IP: [\d\.]*)");
if (m.Success && m.Groups.Count == 4)
{
string site = m.Groups[1].Value;
string domain = m.Groups[2].Value;
string ip = m.Groups[3].Value;
}
If you wany a shorter way, you can use linq instead of regex. Something like:
string[] resultsSCAN = str.Split(new string[] { "SCAN: " }, StringSplitOptions.None).Skip(1).Take(3).ToArray();
resultsSCAN[resultsSCAN.Count() - 1] = resultsSCAN.Last().Split(new string[] { "SYSTEM: " }, StringSplitOptions.None).First();
I think it's what you want.

c# system to display country names without receiving country codes on the phone [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
how can we identify a phone number without a country code ?
DataTable cnc = CNC();
DataTable countrySwitch = CS();
DataRow[] rows;
//string clngnum = dReader["DPC"].ToString();
foreach (DataRow dr in Mdt.Rows)
{
try
{
string ID = dr["ID"].ToString();
//dr["DestinationCountry"] = CountrySwitch(dr["DPC"].ToString());
string Callingnum = dr["CallingNumber"].ToString();
string CalledNum = dr["CalledNumber"].ToString();
if (Callingnum != "" && CalledNum != "" && Callingnum != "0" && Callingnum != "00" && Callingnum != "000")
{
while (Callingnum.Substring(0, 1) == "0")
Callingnum = Callingnum.Remove(0, 1);
In short, you can't. There are several phone number length specifications around the world, and lack of country code can make its resolution dubious.
For example, US follows the North American Numbering Plan, whose format is as follows:
+1 (NPA) NXX-xxxx
Where:
1 - US international Country Calling code
NPA - Numbering Plan Area Code
NXX - Central Office (exchange) code
xxxx - Subscriber Number
Several countries follow the same pattern, and using the same codes for different specifications - for example, the NPA-equivalent field in Brazilian numbering plan relates to state/city, while the NXX-equivalent may have anything between 3 and 5(!) numbers. So, let's assume this valid Brazilian number:
(15) 93935-5555
and this US number (This NPA doesn't exist, just fyi):
[+1]-(593) 935-5555
So, not only you can't because patterns overlap, but also if you're not sure you have the full number it may resolve to the wrong country.

How do I capture integers from a string in C#? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In this project I need to separate the Booking ID from the string below into a separate integer.
Booking ID: 27620
Booked for Paitient(ID): 003
Booked Staff ID: 001
Booked Room: b001
Booked Equipment: Adam
How do I do this in C#?
To clarify: The code above is the whole string, the first line is where the booking ID is contained. I need help finding a way to separate the ID from the string.
I have tried Regex but to no prevail. I cannot get my head around the string formatting.
The ID can be any length.
Regex can handle what you are looking for.
string text = "Booking ID: 27620 ...";
foreach (string line in new LineReader(() => new StringReader(text))
{
string result = Regex.Replace(line, #"[^\d]", "");
Console.WriteLine(result); // >> 27620
}
The regex "[^\d]" says:
[] Capture
^\d Everything that is not (^) a digit (\d)
Then the Replace replaces it all with an empty string.
This would be most valuble if you were looping through each line of your file.
If you needed to keep the field value, then running a simple split would be the better way to go.
string input = "Booking ID: 27620";
Dictionary<string, string> dict =
new Dictionary<string, string>{key = input.Split(':')[0],
value = input.Split(':')[1]};

Categories