W
W
wartur2012-06-01 14:26:57
PHP
wartur, 2012-06-01 14:26:57

What is the correct way to express yourself regularly?

Hello, I am writing a preprocessor for PHP, I need help.

I don’t know why, but I can’t select the necessary parts of the code, the problem is the line break, although the documentation says that .(dot) is any character.

Here at the moment everything is somehow like this

Task:
It is necessary that he also perceive the line break characters.

Here is the pattern
#<\?(.+)\?>#

Here is the text

<?php
$class=get_class($model);
Yii::app()->clientScript->registerScript('gii.crud',"
$('#{$class}_controller').change(function(){
  $(this).data('changed',$(this).val()!='');
});
$('#{$class}_model').bind('keyup change', function(){
  var controller=$('#{$class}_controller');
  if(!controller.data('changed')) {
    var id=new String($(this).val().match(/\\w*$/));
    if(id.length>0)
      id=id.substring(0,1).toLowerCase()+id.substring(1);
    controller.val(id);
  }
});
");
?>
<h1>Crud Generator</h1>

<p>This generator generates a controller and views that implement CRUD operations for the specified data model.</p>

<?php $form=$this->beginWidget('CCodeForm', array('model'=>$model)); ?>

  <div class="row">
    <?php echo $form->labelEx($model,'model'); ?>
    <?php echo $form->textField($model,'model',array('size'=>65)); ?>
    <div class="tooltip">
      Model class is case-sensitive. It can be either a class name (e.g. <code>Post</code>)
        or the path alias of the class file (e.g. <code>application.models.Post</code>).
        Note that if the former, the class must be auto-loadable.
    </div>
    <?php echo $form->error($model,'model'); ?>
  </div>


Here I found interesting information
Wikipedia
It says so:
Metacharacter. (dot) means any single character, but in some implementations excluding the newline character.

So what to do? I have PHP.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
arturphoenix, 2012-06-01
@wartur

Add the s modifier (consider all text as one line) and turn off the "greedy" modifier "+" (note the question mark after the "+"):
#<\?(.+?)\?>#s

M
MastaEx, 2012-06-01
@MastaEx

Add an s modifier.
#<\?(.+)\?>#s

M
Michael, 2012-06-01
@1099511627776

If I understood you correctly, then this is how it turned out #<\?(.+?)\?>#s 5 matches are obtained
But all the same, it’s better to do it with something else and not with a regexp

D
dsd_corp, 2012-06-01
@dsd_corp

The simplest version and do not care about multiline with the s modifier:
#<\?([\x00-\xFF]+)\?>#

D
Denis, 2012-06-01
@uscr

I don't know anything about regular expressions in php, but isn't there an end-of-line character? In python, perl, _a bunch of other names_ - this is "$"

K
Keyten, 2012-06-02
@Keyten

Maybe just force a newline character?
Well instead

.

write
[.\n]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question