[Solved] Finding first five digits in a var with Regex [closed]

You would need to use something like \d{5} which will match 5 digits. Depending on the language you are using you would then access whatever the group matched. For instance, in Java: String str =”AF1400006″; Pattern p = Pattern.compile(“\\d{5}”); Matcher m = p.matcher(str); if(m.find()) System.out.println(m.group()); Which yields the number you are after. An example of … Read more

[Solved] Php Preg Match, how can i do this [closed]

Try to solve an HTML problem with a regular expression, and soon you have two problems. But if you really want to do this with a dirty regular expression, it can be done. You shouldn’t rely on it. The simplest regex is something like: preg_match_all( “/<td class=bilgi_satir width=\”..%\”><b>(.*)<\/b>/i”, $your_html_here, $m ); This returns roughly what … Read more

[Solved] How to extract URL from HTML anchor element using Python3? [closed]

You can use built-in xml.etree.ElementTree instead: >>> import xml.etree.ElementTree as ET >>> url=”<a rel=”nofollow” href=”https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip”>XYZ</a>” >>> ET.fromstring(url).attrib.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” This works on this particular example, but xml.etree.ElementTree is not an HTML parser. Consider using BeautifulSoup: >>> from bs4 import BeautifulSoup >>> BeautifulSoup(url).a.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” Or, lxml.html: >>> import lxml.html >>> lxml.html.fromstring(url).attrib.get(‘href’) “https://stackoverflow.com/example/hello/get/9f676bac2bb3.zip” Personally, I prefer BeautifulSoup – … Read more

[Solved] Want to filter the percentage from my output [closed]

Perldoc is a great resource. Check out perldoc perlretut (tutorial) and perldoc perlre (all the details). Module Regexp::Debugger is also great for visualizing how the matches are happening. Here’s one possible implementation, based on the scant details you provided. #!/usr/bin/env perl use 5.014; use warnings; my $data=”mnttab 0K 0K 0K 54% /etc/mnttab”; my ( $percent … Read more

[Solved] How to separate the contents of parentheses and make a new dataframe column? [closed]

Seems like str.extract would work assuming the seat number is the numeric characters before 席 and the seat arrangement is the values inside the parenthesis: import numpy as np import pandas as pd df = pd.DataFrame({ ‘seat’: [’45席(1階カウンター4席、6〜8人テーブル1席2階地下それぞれ最大20人)’, np.nan, np.nan, np.nan, ‘9席(カウンター9席、個室4席)’] }) new_df = df[‘seat’].str.extract(r'(\d+)席((.*))’, expand=True) new_df.columns = [‘seat number’, ‘seat arrangement’] new_df: seat … Read more

[Solved] php need assistance with regular expression

Your question is not very clear, but I think you mean a solution like this: Edited: Now the hole ranges were shown and not only the specified numbers. <?php $string = “0605052&&-5&-7&-8″; $test=”/^([0-9]+)\&+/”; preg_match($test, $string, $res); if (isset($res[1])) { $nr = $res[1]; $test=”/\&\-([0-9])/”; preg_match_all($test, $string, $res); $result[] = $nr; $nrPart = substr($nr, 0, -1); $firstPart … Read more

[Solved] Regex to seperate a work and decimal number

#!/usr/bin/python2 # -*- coding: utf-8 -*- import re text=”{[FACEBOOK23.1K],[UNKNOWN6],[SKYPE12.12M]}”; m = re.findall(‘\[([a-z]+)([^\]]+)\]’, text, re.IGNORECASE); output=”{“; i = 0 for (name,count) in m: if i>0: output += ‘,’ output += “[“+name+”,”+count+”]” i=i+1 output += ‘}’ print output 4 solved Regex to seperate a work and decimal number