Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex how to find pattern?

Tags:

regex

I need to separate text below with Regex syntax. Actually I found recipes for dddd-dddd and dddd-ddd[x]. What with text? I need to get string with this value like this: "British Journal of Applied Science & Technology". How to write it in regex?

337 British Journal of Applied Science & Technology 2231-0843 5
338 British Journal of Economics, Management & Trade 2278-098X 5
339 British Journal of Education, Society & Behavioural Science 2278-0998 6
340 British Journal of Environment and Climate Change 2231-4784 5
341 British Journal of Mathematics & Computer Science 2231-0851 4
342 British Journal of Medicine and Medical Research 2231-0614 8
343 British Journal of Pharmaceutical Research 2231-2919 4
344 British Microbiology Research Journal 2231-0886 9
345 Bromatologia i Chemia Toksykologiczna 0365-9445 5
346 Budownictwo Górnicze i Tunelowe 1234-5342 5
347 Budownictwo i Architektura 1899-0665 3
348 Budownictwo, Technologie, Architektura 1644-745X 3
349 Builder 1896-0642 2
350 Built Environment 0263-7960 10
351 Bulgarian Journal of Veterinary Medicine 1311-1477 8
352 Bulgarian Medicine 1314-3387 2
353 Bulletin de la Société des sciences et des lettres de Łódź, Série: Recherches sur les déformations 0459-6854 7
354 Bulletin of Alfred Nobel University. Series "Legal Science" 2226-2873 6
355 Bulletin of Geography. Socio-economic Series 1732-4254 10
356 Bulletin of Geography: Physical Geography Series 2080-7686 9
357 Bulletin of the Polish Academy of Sciences. Mathematics 0239-7269 9
358 Business and Economic Horizons 1804-1205 8
359 Business and Economics Research Journal 1309-2448 10
360 Business Process Management Journal 1463-7154 10
like image 660
user5098856 Avatar asked Mar 20 '26 00:03

user5098856


2 Answers

(?<=\d\s)\D+(?=\s\d)

That should find what you need. If you are interested in how it works: The first part of the Regex ((?<=\d\s)) declares that the searched phrase must come after a digit (\d) followd by a whitespace (\s).

The second part (\D+) is what is actually found. It means any number of non digit characters.

The third part ((?=\s\d)) makes sure that the result is followed by another whitespace and digit.

like image 103
Adrodoc Avatar answered Mar 21 '26 14:03

Adrodoc


You can do it with an expression that uses lookahead and lookbehind, like this:

(?<=\d{3}\s).*(?=\s\d{4}-)

This expression requires three digits followed by space in front of the text, and four digits preceded by space and followed by a dash after the text. The name itself is matched by a straight .* pattern.

Demo.

like image 45
Sergey Kalinichenko Avatar answered Mar 21 '26 13:03

Sergey Kalinichenko