Matching fixed number of zeroes before new line

The Onin

I need to match fixed number of zeroes (which are strings), followed by a new line, and delete it from string.

This is the pattern I'm working on:

000000000000000
000000000000000
000000000000000
000100000001000
000010000010000
000001000100000
001000111000100
000100010001000
000010010010000
000001010100000
001000111000100
000100010001000
000010010010000
000001010100000
000000111000000
001111111111100
000000010000000
000000010000000
000000010000000
000000010000000
000000010000000
000000010000000
000000010000000
000000000000000
000000000000000

The PHP code is:

$regex = '/^[0{' . $amount . '}]\n$/m'; // /^[0{15}]\n$/m
$pattern = preg_replace($regex, null, $pattern); // $pattern is pattern above
Aleksei Matiushkin

You don’t need the $ there in regexp (because after \n there are digits again.). The square brackets are used for “one of,” you don’t need them here. I doubt also whether you need a “at the very first position” marker ^. And replacer should be a string:

$regex = '/0{' . $amount . '}\n/m'; // /^[0{15}]\n/m
$pattern = preg_replace($regex, '', $pattern); // $pattern is pattern above

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

vim, how to search text and prepend new line before searched line

분류에서Dev

SSIS new line delimited columns with set number of fields

분류에서Dev

Number () 대 new Number ()?

분류에서Dev

tr :: before number with table?

분류에서Dev

PHP Search Not Matching Line in File

분류에서Dev

Scala Number type pattern matching

분류에서Dev

Matching part before and after underscore of filename

분류에서Dev

linux - add a line just before ending line

분류에서Dev

Logistic stepwise regression with a fixed number of predictors

분류에서Dev

PPPOE : How to Set fixed calling number

분류에서Dev

Assembly Language New Line

분류에서Dev

matplotlib imshow fixed aspect and vertical colorbar matching master axis height

분류에서Dev

regular expressions / pattern matching on ubuntu command line

분류에서Dev

python: number range to regex matching string

분류에서Dev

Return index number of matching item in array

분류에서Dev

Compare two arrays and print number of matching elements

분류에서Dev

Add a line below each line matching a pattern only if not already present

분류에서Dev

Regular Expression for matching number greater than specified decimal number

분류에서Dev

Assign number on specific line to a variable

분류에서Dev

Replacing string based on line number

분류에서Dev

Python replace line by index number

분류에서Dev

Is the last new line on fstab important?

분류에서Dev

How to add new line in a file

분류에서Dev

TCPDF writeHTMLCell new line issue

분류에서Dev

Bash - Remove the last character of the line this before?

분류에서Dev

Reading a fixed length line of integers from a file (bu

분류에서Dev

Wrong number of arguments for model new

분류에서Dev

print varying number of lines before and after a pattern

분류에서Dev

How to format a double with fixed number of significant digits, regardless of the decimal places?

Related 관련 기사

  1. 1

    vim, how to search text and prepend new line before searched line

  2. 2

    SSIS new line delimited columns with set number of fields

  3. 3

    Number () 대 new Number ()?

  4. 4

    tr :: before number with table?

  5. 5

    PHP Search Not Matching Line in File

  6. 6

    Scala Number type pattern matching

  7. 7

    Matching part before and after underscore of filename

  8. 8

    linux - add a line just before ending line

  9. 9

    Logistic stepwise regression with a fixed number of predictors

  10. 10

    PPPOE : How to Set fixed calling number

  11. 11

    Assembly Language New Line

  12. 12

    matplotlib imshow fixed aspect and vertical colorbar matching master axis height

  13. 13

    regular expressions / pattern matching on ubuntu command line

  14. 14

    python: number range to regex matching string

  15. 15

    Return index number of matching item in array

  16. 16

    Compare two arrays and print number of matching elements

  17. 17

    Add a line below each line matching a pattern only if not already present

  18. 18

    Regular Expression for matching number greater than specified decimal number

  19. 19

    Assign number on specific line to a variable

  20. 20

    Replacing string based on line number

  21. 21

    Python replace line by index number

  22. 22

    Is the last new line on fstab important?

  23. 23

    How to add new line in a file

  24. 24

    TCPDF writeHTMLCell new line issue

  25. 25

    Bash - Remove the last character of the line this before?

  26. 26

    Reading a fixed length line of integers from a file (bu

  27. 27

    Wrong number of arguments for model new

  28. 28

    print varying number of lines before and after a pattern

  29. 29

    How to format a double with fixed number of significant digits, regardless of the decimal places?

뜨겁다태그

보관