Sublime Forum

How to make view.find global(multiline)?

#1

How to get multi line matches in view.find. For example:

use abcd;
use efjh;

With view.find("use .*;", 0) it just returns first line(In regex101 with global flag will match both lines). I’ve tried find_all but returns one region per line.

0 Likes

#2

try .|[\r\n] for matching any char

0 Likes

#3

But it view.find('use (.|[\r\n])*;', 0) will match till any ; :

<?php

use Abcd;
use Efgh;

function();

will match till end of file

0 Likes

#6

I am quite confused now what’s the expected result.

0 Likes

#7

I want to match just those use statement lines. And I want to use global flag in view.find. https://regex101.com/r/ZpesuG/1

0 Likes

#8

That looks exactly what find_all does and you’ve mentioned it. So I am confused what’s wrong with find_all?

0 Likes

#9

find_all returns array of regions. Is there a way to get just one?

0 Likes

#10

What’s “one”? Doesn’t your link gives “two”? Doesn’t find give “one”?

0 Likes

#11

I mean one region that specifies two or more lines, not two region per one line

0 Likes

#12

That’s not how region is designed. https://www.sublimetext.com/docs/api_reference.html#sublime.Region

You have to merge them by your own rule.

0 Likes

#13

By the way, those two regions are not “connected” since there is an newline char between them.

0 Likes

#14

In regex101 with global flag it gives 2 separate matches for me.

. matches any character except line terminators (it even says so on the right in regex101), which is what I believe OP wants to change.

Try use (.*\n?)*; instead

0 Likes