Regex for object dimensions

eozzy

http://regexr.com/3eg8c

Text:

(18.8 x 25.7 x 1.8 cm)
10.787 x 8.031 x 1.339"
2.75 x 6.5 x 6.5 in
31 x 21.89 x 1.89 cm 
(18.8 x 25.7 x 1.8 cm)
10.787 x 8.031 x 1.339"
2.75  x  6.5  x  6.5 in
31x21.89x1.89 mm 

Expression:

/(\d*\.?\d+) x (\d*\.?\d+)(?: x (\d*\.?\d+))\s*(cms?|in|inch|inches|mms?)\b/ig

Currently matches some of the values from my test case, but i'd like it to:

  • Make sure exactly 3 values are found (1x2x3) no more, no less.
  • Ignore spaces between the numbers as well as the number and unit.
  • Include unit in the capture group.
Dekel

This change will give you what you are looking for:

/^(?:[\(])?(\d*\.?\d+)\s*x\s*(\d*\.?\d+)\s*x\s*(\d*\.?\d+)\s*((?:cms?|in|inch|inches|mms?)\b|(?:[\"]))/igm

You can check here:
http://regexr.com/3eg8i

This is the breakdown:

  1. start at the beginning of the string ^ (or beginning of line, using the /m modifier at the end)
  2. allow ( but don't catch it (?:[\(])
  3. find a number (\d*\.?\d+) (int or float [with the dot])
  4. have the x char, with (or without) space before and after `\sx\s - support multiple spaces here
  5. have any of the supported units:
    5.1 cm, cms, in, inch, inches, mm, mms - followed by word boundry
    (?:cms?|in|inch|inches|mms?)\b
    OR
    5.2 Have the " char |(?:[\"])

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JavaScript object dimensions

From Dev

Changing object dimensions for different resolutions

From Dev

Font dimensions in different object to JPanel

From Dev

Rotate object to "look at" another object in 3 dimensions?

From Dev

Rotate object to "look at" another object in 3 dimensions?

From Dev

Extract vertical and horizontal dimensions of an irregular object

From Dev

object-fit: get resulting dimensions

From Dev

Change Image() object dimensions (width and height)

From Dev

Dynamically change object dimensions in Three.js

From Dev

Interpolating a multidimensional object along two dimensions in Matlab

From Dev

How to add image dimensions in an image being added via regex

From Dev

How can I get 3D object dimensions in ThreeJS?

From Dev

Sum of matrices in 3-dimensional object of variable dimensions without looping

From Dev

Dimensions of 2d char array from ArrayDeque Object

From Dev

Do the object_detection tensorflow api specific image dimensions?

From Dev

Parsing text to object with regex

From Dev

convert regex string to regex object in javascript

From Dev

How to get regex to return string (not a regex object)?

From Dev

Static regex object or does it matter?

From Dev

Create regex from object keys

From Dev

Create regex from object keys

From Dev

Regex match for object creation in Java

From Dev

Counting array items in object with regex

From Dev

How to force images to cover the dimensions of a layout unit using flexbox and the object-fit property?

From Dev

How to tackle 'attempt to set 'colnames' on an object with less than two dimensions' error in R

From Dev

How can I set a default value to the x and y dimensions of a copied object from excel into autocad?

From Dev

Regex that will match PHP variable but not object and function invocation

From Dev

Regex Style Pattern Matching in .NET Object Lists

From Dev

Python - regex to match url with mongo object id

Related Related

  1. 1

    JavaScript object dimensions

  2. 2

    Changing object dimensions for different resolutions

  3. 3

    Font dimensions in different object to JPanel

  4. 4

    Rotate object to "look at" another object in 3 dimensions?

  5. 5

    Rotate object to "look at" another object in 3 dimensions?

  6. 6

    Extract vertical and horizontal dimensions of an irregular object

  7. 7

    object-fit: get resulting dimensions

  8. 8

    Change Image() object dimensions (width and height)

  9. 9

    Dynamically change object dimensions in Three.js

  10. 10

    Interpolating a multidimensional object along two dimensions in Matlab

  11. 11

    How to add image dimensions in an image being added via regex

  12. 12

    How can I get 3D object dimensions in ThreeJS?

  13. 13

    Sum of matrices in 3-dimensional object of variable dimensions without looping

  14. 14

    Dimensions of 2d char array from ArrayDeque Object

  15. 15

    Do the object_detection tensorflow api specific image dimensions?

  16. 16

    Parsing text to object with regex

  17. 17

    convert regex string to regex object in javascript

  18. 18

    How to get regex to return string (not a regex object)?

  19. 19

    Static regex object or does it matter?

  20. 20

    Create regex from object keys

  21. 21

    Create regex from object keys

  22. 22

    Regex match for object creation in Java

  23. 23

    Counting array items in object with regex

  24. 24

    How to force images to cover the dimensions of a layout unit using flexbox and the object-fit property?

  25. 25

    How to tackle 'attempt to set 'colnames' on an object with less than two dimensions' error in R

  26. 26

    How can I set a default value to the x and y dimensions of a copied object from excel into autocad?

  27. 27

    Regex that will match PHP variable but not object and function invocation

  28. 28

    Regex Style Pattern Matching in .NET Object Lists

  29. 29

    Python - regex to match url with mongo object id

HotTag

Archive